New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex weirdness - capture group not reset #15350
Comments
From choroba@matfyz.czCreated by choroba@matfyz.czThe following regex matches the string abA: perl -lwe 'print for shift =~ /^(([ab])|([ab]))*(\3)$/i' abA The first "a" was matched by a previous iteration of the * (probably See also http://stackoverflow.com/a/37379672/1030675 Thanks Lukas Mai for helping me debug it in #perl at freenode. E. Choroba Perl Info
|
From ambrus@math.bme.huOn Sun May 22 16:15:17 2016, choroba@matfyz.cz wrote:
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. |
The RT System itself - Status changed from 'new' to 'open' |
From choroba@matfyz.czThe problem (as shown in the link) is that when replacing \3 with \2, the regex no longer matches the string, but it still does in egrep. To get more details, you can use use feature qw{ say }; On Mon May 23 04:35:57 2016, b_jonas wrote:
|
From @iabynOn Mon, May 23, 2016 at 04:35:58AM -0700, Zsban Ambrus via RT wrote:
Yes, successful captures are intentionally kept across subsequent e.g. this: "abcde" =~ /(?: (?: ([acd]) | ([bde]) ) (?{ print "1=[$1] 2=[$2]\n" }) )+/x; outputs: 1=[a] 2=[] Closing. -- |
@iabyn - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#128215 (status was 'rejected')
Searchable as RT128215$
The text was updated successfully, but these errors were encountered: