3 unstable releases

0.2.0 Jan 29, 2022
0.1.1 Sep 9, 2020
0.1.0 Aug 31, 2020

#1065 in Rust patterns

Download history 876/week @ 2024-06-16 656/week @ 2024-06-23 618/week @ 2024-06-30 747/week @ 2024-07-07 555/week @ 2024-07-14 657/week @ 2024-07-21 666/week @ 2024-07-28 892/week @ 2024-08-04 836/week @ 2024-08-11 598/week @ 2024-08-18 1072/week @ 2024-08-25 908/week @ 2024-09-01 828/week @ 2024-09-08 800/week @ 2024-09-15 876/week @ 2024-09-22 659/week @ 2024-09-29

3,206 downloads per month
Used in 30 crates (26 directly)

MIT/Apache

7KB

regex-macro

Crates.io Version Docs.rs Latest Build Status

This crate contains a little macro to generate a lazy Regex and remove some boilerplate when compiling regex expressions.

Usage

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"));

License

Licensed under either of

at your option.

Dependencies

~2.2–3MB
~55K SLoC