Skip to content
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

Less greedy named capture groups #690

Closed
wants to merge 1 commit into from
Closed

Conversation

chmln
Copy link

@chmln chmln commented Jun 8, 2020

Hi @BurntSushi

I've forked regex to change capture group matching a bit. In particular, this fixes unexpected behavior like chmln/sd#44, and #602 partially.

This changes the matching so that '$1foo' is parsed as '$1' and 'foo' instead of the variable $1foo. Since named capture groups cannot begin with a number anyways, this is a common-sense change to me.

I'm submitting this pull request in case there's interest in this behavior. And of course, upstreaming the fix is obviously preferable to maintaining a fork.

@BurntSushi
Copy link
Member

There is an issue open for this: #69

It's marked as regex2 because it's a breaking change. Arguably, we might be able to get away with a change like this, but I'd prefer to be conservative about such things.

And of course, upstreaming the fix is obviously preferable to maintaining a fork.

You really do not need to maintain a fork. That's a huge amount of overkill. All you need to do is implement your own replacement routine. Copying out the replacement text parser from the regex crate, make your changes and implement a replace function with it should be pretty easy. Certainly much easier than maintaining a published fork.

@BurntSushi BurntSushi closed this Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants