nom_regex::str

Function re_find

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

Compares the input with a regular expression and returns the first match.

Requires the regexp feature.

ยงExample

let re = regex::Regex::new(r"\d{4}").unwrap();
let parser = re_find::<(&str, ErrorKind)>(re);
assert_eq!(parser("abc2019"), Ok(("", "2019")));
assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::RegexpFind))));
assert_eq!(parser("2019-10"), Ok(("-10", "2019")));