Skip to content

mtfcd/reg_match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
caicong
Jan 7, 2025
2553659 · Jan 7, 2025

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A match style regex tool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages