| Crates.io | winnow-regex |
| lib.rs | winnow-regex |
| version | 0.1.2 |
| created_at | 2025-05-05 07:56:26.759602+00 |
| updated_at | 2025-05-06 10:43:52.6941+00 |
| description | A set of winnow parsers backed by the regex crate |
| homepage | https://github.com/yamaura/winnow-regex |
| repository | https://github.com/yamaura/winnow-regex |
| max_upload_size | |
| id | 1660359 |
| size | 22,477 |
A set of winnow parsers backed by the regex crate.
Provides two generic parsers:
regex(pattern) – match a slice against a regular expression from the beginning.captures(pattern) – match and return captured groups.Both parsers support complete‑and‑partial streaming via the StreamIsPartial trait.
use winnow::prelude::*;
use winnow_regex::regex;
fn digits<'i>(input: &mut &'i str) -> ModalResult<&'i str> {
// matches one or more digits at the front
regex(r"^\d+").parse_next(input)
}
assert_eq!(digits.parse_peek("42abc"), Ok(("abc", "42")));
assert!(digits.parse_peek("abc42").is_err());
use winnow::prelude::*;
use winnow_regex::{captures, Captures};
fn dims<'i>(input: &mut &'i str) -> ModalResult<(i32, i32)> {
// captures two number groups: width and height
captures(r"^(\d+)x(\d+)")
.map(|caps| {
let w: i32 = caps[1].parse().unwrap();
let h: i32 = caps[2].parse().unwrap();
(w, h)
})
.parse_next(input)
}
assert_eq!(dims.parse_peek("800x600rest"), Ok(("rest", (800, 600))));