develooper Front page | perl.perl5.porters | Postings from July 2018

[perl #133352] Ancient Regex Regression

Thread Previous | Thread Next
Hugo van der Sanden via RT
July 10, 2018 19:19
[perl #133352] Ancient Regex Regression
Message ID:
On Sun, 08 Jul 2018 21:04:32 -0700, dcorzine wrote:
> This was my test case, which works with or without anchors:
> "afoobar" =~ /((.)foo|bar)*/
> "afoobar" =~ /^((.)foo|bar)*$/
> Or, as a standalone command:
> perl -e 'print "$2\n" if "afoobar" =~ /^((.)foo|bar)*$/;'
> This prints "b", even though "bfoo" never appears in "afoobar"!
> The correct answer seems to be "a", since that's the last match
> of the inner group and the overall match is successful.

It's by no means clear to me that that must be the correct answer; the other candidate worth considering is that, since in /(...)*/ we return the match for the last iteration of the group, you'd expect further captures embedded within there also to deliver the version from the last iteration of the group.

Under that interpretation, the correct answer would be undef, and the earlier releases that returned 'a' were merely more subtly wrong than the current release.

The fact that other examples don't match such an interpretation argues against it:
% perl -wle 'use Data::Dumper; print Dumper([ "foobar" =~ /((foo)|(bar))*/ ])'
$VAR1 = [
.. but I don't recall seeing docs to justify such results. I'll have to have another wade through them.


via perlbug:  queue: perl5 status: open

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About