https://github.com/selfint/normal
Rust library for writing regular expressions
https://github.com/selfint/normal
Last synced: 11 months ago
JSON representation
Rust library for writing regular expressions
- Host: GitHub
- URL: https://github.com/selfint/normal
- Owner: selfint
- License: mit
- Created: 2023-01-02T21:18:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-11T16:34:21.000Z (over 3 years ago)
- Last Synced: 2025-02-14T08:49:12.775Z (over 1 year ago)
- Language: Rust
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Normal
A simple library for writing readable regular expressions.
Writing regular expressions isn't (usually) an often occurrence. The goal of this library
is to make reading/writing regular expressions easier, now and in the future, and not needing to remember/re-learn the PCRE syntax each time.
In the future, maybe adding full documentation to all the methods/constants can make this
library a way to also learn PCRE syntax.
## Example
```rs
use normal::prelude::*;
let expression = "example"
.then_repeated_between(
2,
5,
named_group(
"name",
"named group"
.then_non_capturing_group("non capturing group")
.then("repeated 2 to 5 times")
),
)
.then(NEWLINE);
let raw = "example(?Pnamed group(?:non capturing group)repeated 2 to 5 times){2,5}\\n";
assert_eq!(expression, raw);
```
## Supported PCRE syntax
Syntax cheat sheet taken from [debuggex.com](https://www.debuggex.com/cheatsheet/regex/pcre).
- [x] Basics:
- [x] then
- [x] |
- [x] Quantifiers:
- [x] *
- [x] +
- [x] ?
- [x] {amount}
- [x] {min,max}
- [x] {min,}
- [x] Groups:
- [x] Un-named - `(...)`
- [x] Named - `(?P...)`
- [x] Non capturing - `(?...)`
- [x] Atomic - `(?>...)`
- [x] Branch reset groups - `(?|...)`
- [x] Match capture group by number - `\Y`
- [x] Match capture group by name - `(?P=name)`
- [x] Match capture group by name or number - `\g{Y}`
- [x] Recurse into pattern - `(?R)`
- [x] Recurse into group by number - `(?Y)`
- [x] Recurse into group by name - `(?&name)`
- [x] Recurse into group by name or number - `\g`
- [ ] Comment - `(?#...)` (do we need this?)
- [x] Constants
- [x] Assertions:
- [x] Positive lookahead - `(?=...)`
- [x] Negative lookahead - `(?!...)`
- [x] Positive lookbehind - `(?<=...)`
- [x] Negative lookbehind - `(?