throop has asked for the wisdom of the Perl Monks concerning the following question:
The (?! will perform a zero-width negative lookahead. But it captures its arg. For example, go in the debugger and let's trim a string up to the first occurance of two consecutive blank lines:
The regex match returned two args. The first is what we wanted (the text up until the two consecutive blank lines) but then we pick up an 'e' from the last match of the (?! \n\n). How can we keep the (?! from capturing?DB<1> $foo = "a\nb\nc\n\nd\ne\n\n\nf\ng\nh\n\ni\n\n\nj\n" DB<2> x $foo =~ /( (:? . | \n (?! \n\n) )+ ) /x 0 'a b c d e' 1 'e'
throop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Non-capturing zero-width negative lookahead
by Sidhekin (Priest) on Mar 22, 2007 at 16:31 UTC | |
|
Re: Non-capturing zero-width negative lookahead
by varian (Chaplain) on Mar 22, 2007 at 16:43 UTC | |
by Sidhekin (Priest) on Mar 22, 2007 at 16:50 UTC |