in reply to Re: A regexp to parse nested brackets containing strings
in thread A regexp to parse nested brackets containing strings

So you can't make $InnerRe anchorred at the beginning, and not anchorred at the beginning, all in the same match invocation.

It's not a problem. My solution even does this.

$\ = "\n"; my $re; $re = qr/ a (??{ $re }) c | b /x; print 'aabcc' =~ /^$re/ ||0; # 1 print '!aabcc' =~ /^$re/ ||0; # 0 First call is anchored to start. print 'a!abcc' =~ /^$re/ ||0; # 0 Recursive call is anchored to pos. print 'aa!bcc' =~ /^$re/ ||0; # 0 Recursive call is anchored to pos.

Replies are listed 'Best First'.
Re^3: A regexp to parse nested brackets containing strings
by rodion (Chaplain) on Sep 24, 2006 at 08:27 UTC
    Looks like I wasn't specific enough in my writeup. Yes, you can put a "^" anchor in the top-level invocation of $re, but not in the $re itself. For the OP's original problem, where he is looking for the innermost parenthesese that are not inside a quote, you want the "^L in the $re. If you don't put it there, the invocation of $re from within the first invocation of $re can just skip over text to find the parentheses within the quotes. However, "^" doesn't do what you need there, because it doesn't mean the beginning of where $re was invoked in each recursive iteration, it means the beginning of this invocation of the regex parser. At least that's what it looks like from the behavior.

      If you don't put it there, the invocation of $re from within the first invocation of $re can just skip over text to find the parentheses within the quotes.

      No, it can't skip. That's what I was showing. If it could skip, all the regexp in my parent post would match, since they would skip over the !. When using (??{ $re }), matching $re is anchored at the current pos..