pub fn regex<'h, Input, Re, Error>(
re: Re,
) -> RegexParser<'h, Input, Re::Output, Error>where
Input: StreamIsPartial + Stream + Offset + Clone,
Re: BytesRegexPattern,
Re::Output: Regex<Haystack<'h> = <Input as Stream>::Slice>,
Re::Error: Debug,
Error: ParserError<Input> + 'static,
Expand description
A &[u8]
-oriented version of [winnow_regex::regex
].
This parser matches the beginning of a byte stream (&[u8]
)
using a regular expression compiled with regex::bytes::Regex
.
It returns the matching slice if the regex matches at offset 0.
For more usage details, see [winnow_regex::regex
].
§Panics
Panics if the regex pattern fails to compile.
§Example
use winnow::prelude::*;
use winnow_regex::bytes::regex;
fn digits<'i>(input: &mut &'i [u8]) -> ModalResult<&'i [u8]> {
regex(r"^\d+").parse_next(input)
}
assert_eq!(digits.parse_peek(b"123abc"), Ok((&b"abc"[..], &b"123"[..])));