develooper Front page | perl.perl5.porters | Postings from May 2016

[perl #128215] Regex weirdness - capture group not reset

Thread Previous | Thread Next
From:
Zsban Ambrus via RT
Date:
May 23, 2016 11:36
Subject:
[perl #128215] Regex weirdness - capture group not reset
Message ID:
rt-4.0.18-4253-1464003357-1570.128215-15-0@perl.org
On Sun May 22 16:15:17 2016, choroba@matfyz.cz wrote:
> The following regex matches the string abA:
> 
> perl -lwe 'print for shift =~ /^(([ab])|([ab]))*(\3)$/i' abA
> b
> b
> a
> A

That looks correct to me.  The regex can match only one way: the first character is matched by the right hand side alternative, the second character is matched by the left hand side alternative, and the third character is matched by the backreference.  As a result, $2 is set from the first character because the left alternative doesn't match later; $1 and $3 are both match from the second character because that's the last time those groups matched; and $4 is set from the last character.



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

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