-
Notifications
You must be signed in to change notification settings - Fork 449
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
Invalid capture group name doesn't fail #602
Comments
Thanks for the report. For clarity, using
A replacement never panics and never returns an error. The only possible behaviors we have here for an invalid capture group name such as
Now, there is enough wiggle room in the language here where we might be justified in changing how invalid capture group names are handled, but the docs even go on to give an example using
It is a bit strange for the example to use an invalid capture group name, but changing the behavior to be in direct contradiction to a documented example is probably a bad idea. I'm going to mark this issue for |
Thanks for your detailed response! My bad not to dig into the docs. But this still kind of confuses me:
So this means |
As I said in my previous comment, it's a bit weird that the docs are using an invalid capture group name as an example. It's plausible that capture group names used to be able to start with a number, and thus, this inconsistency arose. Hmm, indeed, it looks like #87 did that ~4 years ago, which was trying to address #69. |
Okay, I see. Thanks! |
I marked this ticket for regex 2, so I'd like to leave it open. |
Upon reflection, it looks like this is a duplicate of #69, which had been re-opened. |
Example code:
This prints "<>". However, "1a" isn't a valid capture group name (i.e. if you use it like
(?P<1a>...)
it wouldpanic
). When used in a replace expression like the one above, the name "1a" is accepted by the parser (which in theory it shouldn't), and doesn't cause an error to be returned orpanic
.The ideal way to solve this is make the parser only accept
\$\d+
or\$\w[\w\d]*
as valid capture groups.This originally comes from chmln/sd#44.
The text was updated successfully, but these errors were encountered: