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

pub fn captures<F, R, I>(regex: R) -> Captures<F, R, I> where
    F: FromIterator<I::Range>,
    R: Regex<I::Range>,
    I: FullRangeStream,
    I::Range: Range

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::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 "
        ))
    );
}