We don't bite newbies here... much | |
PerlMonks |
Re: Strange regexp behaviorby Chmrr (Vicar) |
on Mar 26, 2002 at 12:50 UTC ( [id://154381]=note: print w/replies, xml ) | Need Help?? |
You're assuming that \1 is magical inside of character classes -- I don't think it is. For example, the following works, and does what you want it to do: perl -pe 's/(")((?!\1).)*\1/check/g'I don't remember how to tell Perl to spit out how it parsed the regex, but that might be useful in proving my point, so I think I'll do that now. ;> Update: Ayup. Here's what perl says about your regex:
Notice that it's taking the \1 to be chr(1), not a backref to the 1st value captured. By contrast, using negative look-ahead:
Well, it's not quite so clear what it's doing anymore (at least to me) But it works, eh? perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'
In Section
Seekers of Perl Wisdom
|
|