unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Regular expression match
@ 2009-11-05  5:02 Qiang
  0 siblings, 0 replies; 5+ messages in thread
From: Qiang @ 2009-11-05  5:02 UTC (permalink / raw)
  To: help-gnu-emacs

Hi

I am trying to use regular expression in Emacs. And I have
question about how to return the matched item. For example,
I want to match and return '8' in the string 'Vol.8'. How
can I achieve that ?

Thanks




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Regular expression match
       [not found] <mailman.10104.1257397298.2239.help-gnu-emacs@gnu.org>
@ 2009-11-05  5:23 ` Pascal J. Bourguignon
  2009-11-05 14:22   ` Kevin Rodgers
       [not found]   ` <mailman.10127.1257432106.2239.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Pascal J. Bourguignon @ 2009-11-05  5:23 UTC (permalink / raw)
  To: help-gnu-emacs

Qiang <mcknight0219@gmail.com> writes:

> Hi
>
> I am trying to use regular expression in Emacs. And I have
> question about how to return the matched item. For example,
> I want to match and return '8' in the string 'Vol.8'. How
> can I achieve that ?

Using groups and match-string.  For example:

(when (re-search-forward "Vol.\(8\)")
   (match-string 1))

-- 
__Pascal Bourguignon__


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Regular expression match
  2009-11-05  5:23 ` Regular expression match Pascal J. Bourguignon
@ 2009-11-05 14:22   ` Kevin Rodgers
  2009-11-05 15:00     ` Timothy Schaeffer
       [not found]   ` <mailman.10127.1257432106.2239.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2009-11-05 14:22 UTC (permalink / raw)
  To: help-gnu-emacs

Pascal J. Bourguignon wrote:
> Qiang <mcknight0219@gmail.com> writes:
> 
>> Hi
>>
>> I am trying to use regular expression in Emacs. And I have
>> question about how to return the matched item. For example,
>> I want to match and return '8' in the string 'Vol.8'. How
>> can I achieve that ?
> 
> Using groups and match-string.  For example:
> 
> (when (re-search-forward "Vol.\(8\)")
>    (match-string 1))

The regexp string should be "Vol\\.\\(8\\)"

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Regular expression match
  2009-11-05 14:22   ` Kevin Rodgers
@ 2009-11-05 15:00     ` Timothy Schaeffer
  0 siblings, 0 replies; 5+ messages in thread
From: Timothy Schaeffer @ 2009-11-05 15:00 UTC (permalink / raw)
  To: help-gnu-emacs


> Pascal J. Bourguignon wrote:
> > Qiang <mcknight0219@gmail.com> writes:
> > 
> >> I am trying to use regular expression in Emacs. And I have question 
> > Using groups and match-string.  For example:
> > 
> > (when (re-search-forward "Vol.\(8\)")
> >    (match-string 1))
> 
> The regexp string should be "Vol\\.\\(8\\)"

And you can avoid emacs' regexp-in-strings hyperquoting with the rx macro.

(rx "Vol." (group "8")) = "Vol\\.\\(8\\)"

Tim S




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Regular expression match
       [not found]   ` <mailman.10127.1257432106.2239.help-gnu-emacs@gnu.org>
@ 2009-11-05 17:19     ` Pascal J. Bourguignon
  0 siblings, 0 replies; 5+ messages in thread
From: Pascal J. Bourguignon @ 2009-11-05 17:19 UTC (permalink / raw)
  To: help-gnu-emacs

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

> Pascal J. Bourguignon wrote:
>> Qiang <mcknight0219@gmail.com> writes:
>> 
>>> Hi
>>>
>>> I am trying to use regular expression in Emacs. And I have
>>> question about how to return the matched item. For example,
>>> I want to match and return '8' in the string 'Vol.8'. How
>>> can I achieve that ?
>> Using groups and match-string.  For example:
>> (when (re-search-forward "Vol.\(8\)")
>>    (match-string 1))
>
> The regexp string should be "Vol\\.\\(8\\)"

Of course.  Sorry.

-- 
__Pascal Bourguignon__


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-11-05 17:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.10104.1257397298.2239.help-gnu-emacs@gnu.org>
2009-11-05  5:23 ` Regular expression match Pascal J. Bourguignon
2009-11-05 14:22   ` Kevin Rodgers
2009-11-05 15:00     ` Timothy Schaeffer
     [not found]   ` <mailman.10127.1257432106.2239.help-gnu-emacs@gnu.org>
2009-11-05 17:19     ` Pascal J. Bourguignon
2009-11-05  5:02 Qiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).