reg_match_macro

Crates.ioreg_match_macro
lib.rsreg_match_macro
version0.1.0
created_at2025-01-06 09:46:07.723113+00
updated_at2025-01-06 09:46:07.723113+00
descriptionHelper crate for reg_match
homepage
repositoryhttps://github.com/mtfcd/reg_match
max_upload_size
id1505424
size8,696
(mtfcd)

documentation

README

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

Commit count: 6

cargo fmt