A safe regular expression library.
forbid(unsafe_code)
no_std
.
abc
[-ab0-9]
, [^ab]
a?
, a*
, a+
, a{1}
, a{1,}
, a{,1}
, a{1,2}
, a{,}
a|b|c
a(bc)?
a(?:bc)?
Partially optimized. Runtime is about 10 times slower than
regex
crate.
Here are relative runtimes measured with
safe-regex-rs/bench
run on a 2018 Macbook Pro:
| regex
| safe_regex
| expression |
| ----- | ---------- | ---------- |
| 1 | 6 | find phone num .*([0-9]{3})[-. ]?([0-9]{3})[-. ]?([0-9]{4}).*
|
| 1 | 18 | find date time .*([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+).*
|
| 1 | 0.9 | parse date time ([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+)
|
| 1 | 30 | check PEM Base64 [a-zA-Z0-9+/]{0,64}=*
|
| 1 | 20-400 | substring search .*(2G8H81RFNZ).*
|
regex
unsafe
code.pcre2
regular-expression
rec
```
Metric output format: x/y x = unsafe code used by the build y = total unsafe code found in the crate
Symbols:
🔒 = No unsafe
usage found, declares #![forbid(unsafecode)]
❓ = No unsafe
usage found, missing #![forbid(unsafecode)]
☢️ = unsafe
usage found
Functions Expressions Impls Traits Methods Dependency
0/0 0/0 0/0 0/0 0/0 🔒 safe-regex 0.2.2 0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex-macro 0.2.2 0/0 0/0 0/0 0/0 0/0 🔒 ├── safe-proc-macro2 1.0.24 0/0 0/0 0/0 0/0 0/0 🔒 │ └── unicode-xid 0.2.1 0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex-compiler 0.2.2 0/0 0/0 0/0 0/0 0/0 🔒 ├── safe-proc-macro2 1.0.24 0/0 0/0 0/0 0/0 0/0 🔒 └── safe-quote 1.0.9 0/0 0/0 0/0 0/0 0/0 🔒 └── safe-proc-macro2 1.0.24
0/0 0/0 0/0 0/0 0/0
```
rust
use safe_regex::{regex, IsMatch, Matcher0};
let matcher: Matcher0<_> =
regex!(br"[abc][0-9]*");
assert!(matcher.is_match(b"a42"));
assert!(!matcher.is_match(b"X"));
rust
use safe_regex::{regex, Matcher2};
let matcher: Matcher2<_> =
regex!(br"([abc])([0-9]*)");
let (prefix, digits) =
matcher.match_all(b"a42").unwrap();
assert_eq!(b"a", prefix);
assert_eq!(b"42", digits);
match_all
return typesrc/bin/uncompilable/main.rs
.tests/dfa_single_pass.rs
and tests/nfa_without_capturing.rs
.MatcherN::new
functions const
.
Cargo.toml
and bump version number.../release.sh
License: Apache-2.0