[][src]Function combine::parser::regex::captures

pub fn captures<F, R, Input>(regex: R) -> Captures<F, R, Input> where
    F: FromIterator<Input::Range>,
    R: Regex<Input::Range>,
    Input: RangeStream,
    Input::Range: Range
This is supported on crate feature regex only.

Matches regex on the input by running captures_iter on the input. Returns the captures of the first match and consumes the input up until the end of that match.

extern crate regex;
extern crate combine;
use regex::Regex;
use combine::Parser;
use combine::parser::regex::captures;

fn main() {
    let mut fields = captures(Regex::new("([a-z]+):([0-9]+)").unwrap());
    assert_eq!(
        fields.parse("test:123 field:456 "),
        Ok((vec!["test:123", "test", "123"],
            " field:456 "
        ))
    );
    assert_eq!(
        fields.parse("test:123 :456 "),
        Ok((vec!["test:123", "test", "123"],
            " :456 "
        ))
    );
}