https://github.com/mirryi/regexp2
Toy regular expressions implementation using finite automata.
https://github.com/mirryi/regexp2
automata regex
Last synced: about 2 months ago
JSON representation
Toy regular expressions implementation using finite automata.
- Host: GitHub
- URL: https://github.com/mirryi/regexp2
- Owner: mirryi
- License: apache-2.0
- Created: 2021-06-23T23:57:09.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-26T03:02:01.000Z (about 3 years ago)
- Last Synced: 2025-02-13T20:17:33.639Z (4 months ago)
- Topics: automata, regex
- Language: Rust
- Homepage:
- Size: 300 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[](https://github.com/mirryi/regexp2/actions)
[](https://crates.io/crates/regexp2)
[](https://docs.rs/regexp2)# RegExp2
A toy regular expressions implementation.
# Usage
The following operators are supported:
- `*` : the Kleene star
- `+` : the "plus" operator, where `a+` is equivalent to `aa*` or
`a*a`
- `?` : the optional operator
- `|` : the union operator
- `(` and `)` : grouping
- \\ : escaping meta-characters
- `[abc]` : character classes with character ranges `[A-Z0-9]`
- `[^abc]` : negation of character classes
- `\n` : newline
- `\d`, `\D` : all Unicode decimal number characters and all non-decimal
number characters, respectively
- `\w`, `\W` : all word characters (alphanumeric and `_`) and non-word
characters, respectively
- `\s`, `\S` : all whitespace and non-whitespace characters, respectively
- `.` : any character except newline (`\n`)A fairly arbitrary usage example:
```rust
use regexp2::RegExp;fn main() {
// Any sequence of a's and b's ending in abb.
let mut re = RegExp::new("(a|b)*abb").unwrap();
assert!(re.is_match("abb"));
assert!(re.is_match("aababb"));// Any sequence of characters that are not B, C, D, E, F or any lowercase
// letter.
re = RegExp::new("[^B-Fa-z]*").unwrap();
assert!(re.is_match("AGAQR"));// Any sequence of at least one digit followed by nothing or an
// alphanumeric or underscore.
re = RegExp::new(r"\d+\w?").unwrap();
assert!(re.is_match("3a"));
assert!(re.is_match("08m"));
assert!(re.is_match("999_"));
}
```