Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Negative Lookahead Assertion Strangnessby kvale (Monsignor) |
on May 15, 2006 at 16:37 UTC ( [id://549541]=note: print w/replies, xml ) | Need Help?? |
In example 3, the lookahead assertion doesn't match at the beginning of the string, so the regex tries to match at the next position in the string, that fails and so on. This continues until the regex matches at position "oo then..." in which case no foo is found and it succeeds.
In example 4, the .* will first eat the whole string and then the foo will fail to match, satisfying the negative assertion :). So the whole string is printed. Both of these examples show the danger of creating nonlocal assertions. It is easy to do something unexpected when the string tested is some distance from the assertion. -Mark
In Section
Seekers of Perl Wisdom
|
|