https://github.com/rust-bakery/nom-regex
https://github.com/rust-bakery/nom-regex
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rust-bakery/nom-regex
- Owner: rust-bakery
- License: mit
- Created: 2021-07-19T20:17:55.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-06-07T07:32:26.000Z (about 4 years ago)
- Last Synced: 2025-06-27T00:22:12.203Z (12 months ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nom-regex
This crate provides combinators for [nom parser combinators](https://crates.io/crates/nom) using the [regex](https://crates.io/crates/regex) crate.
## Example
```rust
use nom::{Err, error::ErrorKind};
use nom_regex::str::re_match;
fn main() {
let re = regex::Regex::new(r"^\d{4}").unwrap();
let parser = re_match::<(&str, ErrorKind)>(re);
assert_eq!(parser("2019"), Ok(("", "2019")));
assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::RegexpMatch))));
assert_eq!(parser("2019-10"), Ok(("", "2019-10")));
}
```