Module combine::parser::regex

source ·
Available on crate feature regex only.
Expand description

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 (&).

Enabled using the regex feature (for regex-0.2) or the regex-1 feature for regex-1.0.

use once_cell::sync::Lazy;
use regex::{bytes, Regex};
use combine::Parser;
use combine::parser::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""[..]))
    );

    static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new("[:alpha:]+").unwrap());
    assert_eq!(
        match_(&*REGEX).parse("abc123"),
        Ok(("abc123", "abc123"))
    );
}

Structs§

Traits§

Functions§

  • 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.
  • 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<Input::Range>. Consumes all input up until the end of the last match.
  • 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.
  • Matches regex on the input by running find_iter on the input. Returns all matches in a F: FromIterator<Input::Range>. Consumes all input up until the end of the last match.
  • Matches regex on the input returning the entire input if it matches. Never consumes any input.