in reply to Unexpected regular expression match
You seem to think backtracking cannot occur within (?>PAT). That's not the case at all.
The purpose of (?>PAT) is to prevent the regex engine from trying to get PAT to match something else once it has already matched something. In short, backtracking through (?>PAT) causes it to fail.
You want
/^\d+ _\d+ (?> (?:_\d+)? ) \w+ $/x
which can also be written as
/^\d+ _\d+ (?:_\d+)?+ \w+ $/x
For "1_0_1" =~ /^\d+ _\d+ (?> (?:_\d+)? ) \w+ $/x, everything is straightforward until /\w+/ fails to match. At that point, the regex engine starts to backtrack.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unexpected regular expression match
by ikegami (Patriarch) on Jan 26, 2012 at 00:43 UTC | |
|
Re^2: Unexpected regular expression match
by GrandFather (Saint) on Jan 26, 2012 at 02:34 UTC | |
by ikegami (Patriarch) on Jan 26, 2012 at 04:14 UTC |