dalias at aerifal.cx
Fri Sep 29 05:53:46 UTC 2006
On Thu, Sep 28, 2006 at 04:47:31PM -0700, Tony Lin wrote:
> Greetings list.
> Is it possible to match on nth instance of a marked subexpression? For
> example, with the string:
> "hello _world_ !!!"
> I would like to extract the world "world". The closest I can get to is
> using the regex expression:
> This gives me two subexpression matches
> 1. "_world_"
> 2. "world"
> I can't seem to be able to select the 2nd subexpression using
> "_(.*)_\2", I guess it's not supported?
No, it just means you don't understand regex. "_(.*)_\2" as a BRE
means that you want to match text between _'s followed by another
occurrance of the second parenthesized subexpression (but there is
none so it will never match). "_(.*)_\1" cold match _world_world or
_xxx_xxx or _123_123 etc.
You haven't explained at all what program you're using or what you're
trying to do. What you said above about the 2 subexpression matches is
correct (except that they're called 0 and 1, not 1 and 2), but
actually using them is a matter of what the calling program does with
the results of regexec() call..
More information about the uClibc