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:
Compiling REx `(")[^\1]*\1' size 19 first at 3 1: OPEN1(3) 3: EXACT <">(5) 5: CLOSE1(7) 7: STAR(17) 8: ANYOF[\0\2-\377](0) 17: REF1(19) 19: END(0)
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:
Compiling REx `(")((?!\1).)*\1' size 24 first at 3 1: OPEN1(3) 3: EXACT <">(5) 5: CLOSE1(7) 7: CURLYM[2] {0,32767}(22) 11: UNLESSM[-0](17) 13: REF1(15) 15: SUCCEED(0) 16: TAIL(17) 17: REG_ANY(20) 20: SUCCEED(0) 21: NOTHING(22) 22: REF1(24) 24: END(0)
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 reply to Re: Strange regexp behavior
by Chmrr
in thread Strange regexp behavior
by wine
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |