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

backreference tries to match impossible capture names. #399

Closed
fulara opened this issue Sep 6, 2017 · 2 comments
Closed

backreference tries to match impossible capture names. #399

fulara opened this issue Sep 6, 2017 · 2 comments

Comments

@fulara
Copy link
Contributor

fulara commented Sep 6, 2017

Sorry about confusing topic - below fragment should be self explanatory.

extern crate regex;

use regex::Regex;

fn main() {
   let r = Regex::new("(a)").unwrap();
   let result = r.replace_all("xax", "$1Q").into_owned();
   assert_eq!("xaQx", result); // fails, result is xax
}

I think the replace should see the capture name $1 since Q is not a number. Especially that you are not allowed to create a capture names starting with numbers see this error message:

Capture names must consist of [_a-zA-Z0-9] and are not allowed to start with with a number.

This works as I expected in sed and notepad++.

@BurntSushi
Copy link
Member

This is expected behavior. In fact, this particular case is even called out explicitly in the documentation: https://docs.rs/regex/0.2.2/regex/struct.Captures.html#method.expand --- It even tells you how to fix it. :-)

If you're not reporting this as a bug but instead a feature request, then I think I'd disagree. I'd rather stick to simple rules.

@fulara
Copy link
Contributor Author

fulara commented Sep 7, 2017

Okay. :)
I've missed this in the doc.
I've created a small test which would tell someone like me about that usage, you can merge that if you want. :)

I raised it as a bug.

@fulara fulara closed this as completed Sep 7, 2017
BurntSushi pushed a commit that referenced this issue Dec 30, 2017
BurntSushi pushed a commit that referenced this issue Dec 30, 2017
BurntSushi pushed a commit that referenced this issue Dec 30, 2017
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

No branches or pull requests

2 participants