nom_regex::str

Function re_matches

Source
pub fn re_matches<'a, E>(
    re: Regex,
) -> impl Fn(&'a str) -> IResult<&'a str, Vec<&'a str>, E>
where E: ParseError<&'a str>,
Expand description

Compares the input with a regular expression and returns all matches in a Vec.

Requires the regexp feature.

ยงExample

let re = regex::Regex::new(r"a\d").unwrap();
let parser = re_matches::<(&str, ErrorKind)>(re);
assert_eq!(parser("a1ba2"), Ok(("", vec!["a1", "a2"])));
assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::RegexpMatches))));