Regexm v0.2.0 - A Rust macro for writing regex pattern matching

regexm is a Rust macro for writing regex pattern matching.

New feature: Capture groups

You can use Capture groups like the following.

fn main() {
    let text1 = "2020-01-02";
    regexm::regexm!(match text1 {
        // capture groups
        captures(r"^(\d{4})-(\d{2})-(\d{2})$") => |caps| println!(
            "year: {}, month: {}, day: {}",
            caps.get(1).map_or("", |m| m.as_str()),
            caps.get(2).map_or("", |m| m.as_str()),
            caps.get(3).map_or("", |m| m.as_str())
        ),
        _ => println!("default"),
    });
}

Output:

2020
01
02
2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.