Macro safe_regex::regex[][src]

regex!() { /* proc-macro */ }

Compiles a regular expression into a Rust type.

Returns a MatcherN struct where N is the number of capturing groups.

Specify the type of the expected matcher so your editor can show its functions and documentation: let matcher: Matcher0<_> = regex!(br".").

Examples

use safe_regex::{regex, IsMatch, Matcher0};
let matcher: Matcher0<_> = regex!(br"[abc][0-9]*");
assert!(matcher.is_match(b"a42"));
assert!(!matcher.is_match(b"X"));
use safe_regex::{regex, IsMatch, Matcher2};
let matcher: Matcher2<_> = regex!(br"([abc])([0-9]*)");
let (prefix, digits) = matcher.match_all(b"a42").unwrap();
assert_eq!(b"a", prefix.unwrap());
assert_eq!(b"42", digits.unwrap());