GrandFather has asked for the wisdom of the Perl Monks concerning the following question:
I wanted a regex to match milestone version numbers where the version number could have two or three numbers and an optional milestone suffix. The following test code partially works:
for my $entry (qw(1_0 1_0_1 1_0_beta 1_0_1_beta)) { print "$entry\n" if $entry =~ /^\d+ _\d+ (?> (?:_\d+)? \w+) $/x; }
Prints:
1_0_1 1_0_beta 1_0_1_beta
The 1_0_1 is unexpected (and unwanted). I would have thought the no backtracking section should prevent matching the trailing _1 because (?:_\d+) would match and the backtracking suppression would then cause the \w+ part of the match to fail. What have I misunderstood?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected regular expression match
by ikegami (Patriarch) on Jan 26, 2012 at 00:24 UTC | |
by ikegami (Patriarch) on Jan 26, 2012 at 00:43 UTC | |
by GrandFather (Saint) on Jan 26, 2012 at 02:34 UTC | |
by ikegami (Patriarch) on Jan 26, 2012 at 04:14 UTC | |
|
Re: Unexpected regular expression match
by i5513 (Pilgrim) on Jan 25, 2012 at 23:37 UTC |