|
|
| Perl: the Markov chain saw | |
| PerlMonks |
Re: Look-Arounds in Regexes are Hard (Common Use of a Negative Lookahead)by ikegami (Pope) |
| on Jul 24, 2009 at 08:42 UTC ( #782882=note: print w/ replies, xml ) | Need Help?? |
|
I view
as the equivalent of
except it can prevent the match of entire regexps instead of a choice of characters. I call it the common use of a negative lookahead. If you're using a negative lookahead, that construct will probably satisfy your needs. Keep in mind that both expressions can successfully match 0 characters if not properly anchored. I think it would be nice if /(?^$re)/ could be added as a shortcut to /(?:(?!$re)(?s:.)*/. It would be more readable, and it would help prevent the common misuse of negative lookahead (/(?!$re.*)/). Update: Formatting.
In Section
Meditations
|
|
||||||||||||||||||||||||