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
In reply to Non-capturing zero-width negative lookahead by throop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |