Skip to content

Invalid capture group name doesn't fail #602

Closed
@crides

Description

@crides

Example code:

use regex::Regex;

fn main() {
    let re = Regex::new(r"a(.*)f").unwrap();
    println!("{}", re.replace("asdf", "<$1a>"));
}

This prints "<>". However, "1a" isn't a valid capture group name (i.e. if you use it like (?P<1a>...) it would panic). 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 or panic.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions