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(®ex).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§
- captures
- Matches
regexon the input by runningcaptures_iteron the input. Returns the captures of the first match and consumes the input up until the end of that match. - captures_
many - Matches
regexon the input by runningcaptures_iteron the input. Returns all captures which is part of the match in aF: FromIterator<Input::Range>. Consumes all input up until the end of the last match. - find
- Matches
regexon the input by runningfindon the input and returns the first match. Consumes all input up until the end of the first match. - find_
many - Matches
regexon the input by runningfind_iteron the input. Returns all matches in aF: FromIterator<Input::Range>. Consumes all input up until the end of the last match. - match_
- Matches
regexon the input returning the entire input if it matches. Never consumes any input.