Function nom::regexp::str::re_find [−][src]
pub fn re_find<'a, E>(
re: Regex
) -> impl Fn(&'a str) -> IResult<&'a str, &'a str, E> where
E: ParseError<&'a str>,
This is supported on crate feature
regexp
only.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")));