#match #regex #macro #reg-match

macro reg_match_macro

Helper crate for reg_match

1 unstable release

new 0.1.0 Jan 6, 2025

#1282 in Text processing

Download history 110/week @ 2025-01-01

110 downloads per month
Used in reg_match

Custom license

8KB
166 lines

reg_match!

中文

Regex capturing is a very handy tool for extracting strings, but it can't be used directly in a match statement. This macro provides a more convenient method:

// use reg_match;

let input = "123abc";
let output = reg_match!(input {
    r"(?<digits>\d+)(?<letters>.+)" => format!("{}-{}", letters, digits),
    _ => "".to_string()
});
assert_eq!("abc-123", output);

By using the reg_match! macro, you can directly extract variables from named capture groups within the expression.

inspired by

structre

Dependencies

~1–1.8MB
~49K SLoC