pub fn re_capture<'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
the capture groups of the first match in a Vec
.
Requires the regexp
feature.
ยงExample
let re = regex::Regex::new(r"(a)(\d)").unwrap();
let parser = re_capture::<(&str, ErrorKind)>(re);
assert_eq!(parser("a1ba2"), Ok(("ba2", vec!["a1", "a", "1"])));
assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::RegexpCapture))));