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
Fix numbered group binding #585
Conversation
Reading the docs, I actually think the current implementation is correct:
In the motivating example, If that's correct: should we keep the existing behavior or make the change? I have a patch that adds a couple tests in the former case |
Unfortunately, I think we're going to want to keep the existing behavior. Making this change now would be a breaking change. If the docs and implementation differed (where the docs stated the ideal behavior), then I might be willing to call this an implementation bug and fix it. But since the docs and implementation match, I don't think we can get away with fixing this. So I think perhaps some more test on the current behavior would be great. I will mark #69 as a regex2 issue. |
OK no problem, I'll update with a couple of tests. Any other issues where a beginner can contribute? This was the easiest I could find where you pointed to a function and specified the change... |
@BurntSushi this ended up not being much - but still worth merging? Anything else needed? |
Gentle ping to push a notification! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
Ref #69 should
re.replace("ab","$1_$2")
equal"a_b"
or"ab"
?In this test
$42a
binds as a single group reference; which would suggest$1_
did the same (I think?)Here it looks like any non-number character following the number does not bind, and so
$42a
would only bind the42
. I'm no regex expert but a cursory look suggests there's are various approaches to valid number references: https://www.regular-expressions.info/replacebackref.htmlAs an initial attempt, I changed the test case referenced above.
Let me know if this is reasonable