pub fn re_captures<'a, E>(
re: Regex,
) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], Vec<Vec<&'a [u8]>>, E>where
E: ParseError<&'a [u8]>,
Expand description
Compares the input with a regular expression and returns
the capture groups of all matches in a nested Vec
.
Requires the regexp
feature.
ยงExample
let re = regex::bytes::Regex::new(r"(a)(\d)").unwrap();
let parser = re_captures::<(&[u8], ErrorKind)>(re);
assert_eq!(parser(&b"a1ba2"[..]), Ok((&b""[..], vec![vec![&b"a1"[..], &b"a"[..], &b"1"[..]], vec![&b"a2"[..], &b"a"[..], &b"2"[..]]])));
assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::RegexpCapture))));