in reply to Regular Expresssion TroubleShoot Help plz
I think the problem is simply that the [^\1]+ is greedy. Changing it to [^\1]+? seems to work:
Output:$foo = qq{^snafu^|^foobar^\n}; $foo =~ m/\A(\W) # \A instead of ^ and match first non-word [^\1]+? # Match everything that isn't in \1 \1(\W) # Match non-word following the 2nd \1 /xms; $text_qual = $1; $field_sep = $2; print "[$text_qual]\n"; print "[$field_sep]\n";
[^] [|]
Update: Nope I think I'm at least partially wrong too. Greedy or not, if \1 is ^, then [^\1]+ should stop at the first ^.
Changing [^\1]+ to the hardcoded [^^]+ shows that greedyness doesn't matter. So it does appear to have something to do with \1 inside character classes.
Update 2: I think .*? instead of [^\1]+ might work, but it contains the dreaded dot-star. I assume the real solution uses some form of lookahead, but I've never been good with those.
|
|---|