Crates.io | regex-macro |
lib.rs | regex-macro |
version | 0.2.0 |
source | src |
created_at | 2020-08-31 09:02:11.027658 |
updated_at | 2022-01-29 13:39:04.765142 |
description | A macro to generate a lazy regex expression |
homepage | |
repository | https://github.com/rossmacarthur/regex-macro |
max_upload_size | |
id | 282986 |
size | 16,669 |
This crate contains a little macro to generate a lazy
Regex
and remove some
boilerplate when compiling regex expressions.
Generally you want to avoid compiling a regex multiple times. The regex
crate suggests using lazy_static
for this but you can also use once_cell
which is what this crate uses. For example:
use regex_macro::regex;
let re = regex!("[0-9a-f]+");
assert!(re.is_match("1234deadbeef"));
Which is equivalent to the following.
use once_cell::sync::Lazy;
use regex::Regex;
let re = {
static RE: Lazy<Regex> = Lazy::new(|| Regex::new("[0-9a-f]+").unwrap());
&*RE
};
assert!(re.is_match("1234deadbeef"));
Licensed under either of
at your option.