|
|
|
Clear questions and runnable code get the best and fastest answer |
|
| PerlMonks |
Quirky regex bugby japhy (Canon) |
| on Jan 07, 2002 at 02:28 UTC ( #136718=perlmeditation: print w/ replies, xml ) | Need Help?? |
|
I fixed a quirky bug in the regex engine this morning, thanks to converter's test case. It was due to an over-active optimization. The optimization is "if the regex starts with .*, pretend it started with ^.*" and it makes sense -- since .* will have exhausted itself by the time the regex has failed, there's no sense in trying to match anywhere later in the string.
However, this happens even if the .* is being captured and referenced later in the regex (a back-reference). That's no good, as shown by the test case:
"abc123bc" =~ /(.*)\d+\1/; I've patched Perl, but in retrospect, I should make sure I find a backreference too. That shouldn't be too bad, though. Ruby has this bug too. Both can side-step it with a little trick: put .{0} or (?=) as the first thing in your regex; that way, the dot-star isn't the first thing the regex engine sees. Really. Python is free from this bug as of its latest release, 2.2.
_____________________________________________________
Back to
Meditations
|
|
||||||||||||||||||||||||