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

Improper Regex::replace behaviour #291

Closed
ConnorGray opened this issue Oct 27, 2016 · 3 comments
Closed

Improper Regex::replace behaviour #291

ConnorGray opened this issue Oct 27, 2016 · 3 comments

Comments

@ConnorGray
Copy link

ConnorGray commented Oct 27, 2016

The regular express ((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$ is a match on the text "CIMG2341" but expected result of regex.replace("CIMG2341", "$n") returns "2341" is not found, instead "CIMG2341" is returned. The correct behavior is observer when the original regex is replaced with ((MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$.

extern crate regex;

use regex::{Regex};

fn main() {
    let text = "CIMG2341";

    let regex = Regex::new(
        "((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$").unwrap();

    assert!(regex.is_match(text)); // This works (no panic)

    let renamed = regex.replace(text, "$n");
    assert_eq!(renamed, "2341"); // This panics
}
@mbrubeck
Copy link
Contributor

This is a regression from 6300490 (#290).

BurntSushi added a commit to BurntSushi/regex that referenced this issue Oct 27, 2016
This is another variant of incorrectly producing an unambiguous set of
literals.

Fixes rust-lang#291.
@BurntSushi
Copy link
Member

@ConnorGray Thanks again for the bug report! This should be fixed in regex 0.1.80 and regex-syntax 0.3.9 on crates.io.

@ConnorGray
Copy link
Author

@BurntSushi Thanks again for the quick fix!

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

3 participants