Module combine::regex [] [src]

Module containing regex parsers. Module containing regex parsers on streams returning ranges of &str or &[u8].

All regex parsers are overloaded on &str and &[u8] ranges and can take a Regex by value or shared reference (&)

extern crate regex;
#[macro_use]
extern crate lazy_static;
extern crate combine;
use regex::{bytes, Regex};
use combine::Parser;
use combine::regex::{find_many, match_};

fn main() {
    let regex = bytes::Regex::new("[0-9]+").unwrap();
    // Shared references to any regex works as well
    assert_eq!(
        find_many(&regex).parse(&b"123 456 "[..]),
        Ok((vec![&b"123"[..], &b"456"[..]], &b" "[..]))
    );
    assert_eq!(
        find_many(regex).parse(&b""[..]),
        Ok((vec![], &b""[..]))
    );

    lazy_static! { static ref REGEX: Regex = Regex::new("[:alpha:]+").unwrap(); }
    assert_eq!(
        match_(&*REGEX).parse("abc123"),
        Ok(("abc123", "abc123"))
    );
}

Structs

Captures
CapturesMany
Find
FindMany
Match

Traits

MatchFind
Regex

Functions

captures

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.

captures_many

Matches regex on the input by running captures_iter on the input. Returns all captures which is part of the match in a F: FromIterator<I::Range>. Consumes all input up until the end of the last match.

find

Matches regex on the input by running find on the input and returns the first match. Consumes all input up until the end of the first match.

find_many

Matches regex on the input by running find_iter on the input. Returns all matches in a F: FromIterator<I::Range>. Consumes all input up until the end of the last match.

match_

Matches regex on the input returning the entire input if it matches. Never consumes any input.