Macro regex
#[macro_export]
macro_rules! regex {
($re:literal) => { ... };
}
A convenient way to construct regex patterns from string literals.
This macro can be used to construct reusable instances of Regex with
reduced boilerplate. The constructed Regex is stored in a static so the
pattern is compiled approximately once, even when called multiple times.
There is no compile-time checking of patterns with regex!. Instead,
invalid patterns will panic the first time the regex is used. Invalid
patterns should still not be used with regex!; if compile-time checking
becomes feasible in the future, it may be added within a non-semver-breaking
release. In the meantime, consider enabling clippy::invalid_regex.
Examples
use ;
assert!;
assert!;
let re: &Regex = regex!;
assert_eq!;
An invalid pattern will panic when it is first used:
use regex::regex;
let re = regex!("invalid -> ("); // no panic here
re.is_match("invalid -> ("); // panic!