Skip to content

support named capture groups #2

@jtmoon79

Description

@jtmoon79

Named capture groups allow accessing a capture by a str.

using regex

From the regex docs

use regex::Regex;

let re = Regex::new(r"Homer (?<middle>.)\. Simpson").unwrap();
let hay = "Homer J. Simpson";
let Some(caps) = re.captures(hay) else { return };
assert_eq!("J", &caps["middle"]);

Notice the (?<middle>.) with syntax ?<middle> to declare that capture group name middle.

using ere

Using ere, this indexed capture group compiles

use ::ere::{compile_regex, Regex};

const MY_REGEX1: Regex<2> = compile_regex!(r"Homer (.)\. Simpson");

and this named capture group fails

use ::ere::{compile_regex, Regex};

const MY_REGEX1: Regex<2> = compile_regex!(r"Homer (?<middle>.)\. Simpson");

with

An atom was expected but was invalid due to being a special character: `)`

Feature Request

Can ere add support for named capture groups?
I'd love to use them in my project.
Cool project! 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions