#regex #macro #lazy

regex-macro

A macro to generate a lazy regex expression

3 unstable releases

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

#1074 in Rust patterns

Download history 92/week @ 2022-11-27 149/week @ 2022-12-04 209/week @ 2022-12-11 202/week @ 2022-12-18 111/week @ 2022-12-25 206/week @ 2023-01-01 111/week @ 2023-01-08 171/week @ 2023-01-15 125/week @ 2023-01-22 218/week @ 2023-01-29 162/week @ 2023-02-05 191/week @ 2023-02-12 144/week @ 2023-02-19 101/week @ 2023-02-26 344/week @ 2023-03-05 295/week @ 2023-03-12

898 downloads per month
Used in 11 crates (8 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

~1–1.3MB
~38K SLoC