-
Notifications
You must be signed in to change notification settings - Fork 51
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
Group references are not taken into account when group is reporting the last match #296
Comments
Original comment by Matthew Barnett (Bitbucket: mrabarnett, GitHub: mrabarnett). Is it a bug? Probably, though it's not obvious what it should be. Would you expect this:
? If you wanted this to work:
you'd need group 1 to be saved and restored. (Perl and PCRE do this, which is why this module does too.) In your first example, group 'x' matches twice, capturing Your 2 examples can't be equivalent without breaking something else. That's regex for you! |
Original comment by Lars Schmidt-Thieme (Bitbucket: lst2015, ). Currently it looks inconsistent as
Both ways to make it consistent would make sense to me: a) either that
or
For your second example, in case a) I would expect the outcome
as references are ignored, while in case b) to be
as group 1 is referenced as part of the overall regex reference Does this make sense? |
Original comment by Matthew Barnett (Bitbucket: mrabarnett, GitHub: mrabarnett). Consider the final example. If group 1 finishes with the value 'b', then the final In order to use recursion to match like this, which is what Perl and PCRE do, the groups have to be saved when a subroutine is called and restored when it returns. Group 1 captures 'a', calls the subroutine, captures 'b', matches 'b' with the backreference, returns from the subroutine, and then matches 'a' with the backreference. Group 1 has been restored to its previous match. The question is what |
Original comment by Matthew Barnett (Bitbucket: mrabarnett, GitHub: mrabarnett). I've come to a conclusion/decision here: it might be unexpected, but it's not a bug.
|
Original report by Anonymous.
group
is supposed to yield the last match of a group of a regular expression, whilecaptures
will yield all matches. When usinggroup
for a group with a group reference, the last match only of the named group is returned bygroup
, ignoring the matches of the references returned bycaptures
:Without a reference, just copying the named group, it works as expected:
I assume this is not intended behavior but a bug, right?
I used regex 2018.8.29, Python 3.6.5 and opensuse 15.0.
The text was updated successfully, but these errors were encountered: