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

[perl #133352] Ancient Regex Regression

Thread Previous | Thread Next
From:
Hugo van der Sanden via RT
Date:
July 10, 2018 19:19
Subject:
[perl #133352] Ancient Regex Regression
Message ID:
rt-4.0.24-6741-1531250370-889.133352-15-0@perl.org
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 = [
          'bar',
          'foo',
          'bar'
        ];
% 
.. but I don't recall seeing docs to justify such results. I'll have to have another wade through them.

Hugo

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=133352

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About