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/; We'd like $1 to be "bc", but Perl implicitly anchors this regex to the beginning of the string, and thus fails.
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.
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quirky regex bug
by Corion (Patriarch) on Jan 07, 2002 at 02:35 UTC | |
by japhy (Canon) on Jan 07, 2002 at 02:41 UTC |