Macro safe_regex_macro::regex[][src]

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

Compiles a regular expression into a Rust type.

Returns a Matcher struct with a match_all function that takes a byte string.

The Matcher<T> struct is zero-length. Its parameter T is the regex type.

Examples

use safe_regex::{regex, Matcher};
let re: Matcher<_> = regex!(br"(ab)?c");
assert_eq!(None, re.match_all(b""));
assert_eq!(None, re.match_all(b"abcX"));

let groups1 = re.match_all(b"abc").unwrap();
assert_eq!(b"ab", groups1.group(0).unwrap());
assert_eq!(0..2, groups1.group_range(0).unwrap());

let groups2 = re.match_all(b"c").unwrap();
assert_eq!(None, groups2.group(0));
assert_eq!(None, groups2.group_range(0));

// groups2.group(1); // panics