
Regular Expressions: Negating bracketed strings
Quote:
>I want to find every occurrence of ABC _not_ followed by XX\d+ (e.g.
>ABCXX123 is fine, ABCXY123 is not). I tried using this:
>/ABC[^(XX\d+)]/
>which doesn't work - I guess everything within [] is just being treated
>as a character class, so the parentheses and + lose their meta-ness.
um... ABCXX123 is FINE? but by your regex, it looks like you DON'T want
XX\d+
well... this should work:
/ABC(?!XX\d+)/
The (?!...) is the negative look-ahead operator... it means: when whatever
is NOT followed by whatever is here in parens ().
The opposite is (?=...). it means: when whatever IS followed by whatever
is here in parens ()...
check out "man perlre" for more on this.
----------------
| "I don't contemplate it, I just sit and think about it."
| - Sonia Balsky
----------------
** I can be found on #perl on irc.ais.net as jpinyan **
- geek code -
GCS/IT d- s>+: a--- C+>++ UAIS+>$ P+++$>++++ L E--->---- W++$
N++ !o K--? w>+ !O M>- V-- PS PE+ !Y !PGP t+ !5 X+ R tv+ b>+
DI+++ D+>++ G>++ e- h- r y?