A safe regular expression library.
forbid(unsafe_code)
O(n * r * 2^g)
where
n
is the length of the data to checkr
is the length of the regexg
is the number of capturing groups in the regex
TODO(mleonhard) Confirm this with a benchmark..
abc
[-ab0-9]
, [^ab]
a?
, a*
, a+
, a{1}
, a{1,}
, a{,1}
, a{1,2}
, a{,}
a|b|c
a(b*)?
std::collections::HashSet
during matching.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.1.0 0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex-macro 0.1.0 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.1.0 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 saferegex::{regex, Matcher}; let re: Matcher<_> = regex!(br"(ab)?c"); asserteq!(None, re.matchall(b"")); asserteq!(None, re.match_all(b"abcX"));
let groups1 = re.matchall(b"abc").unwrap(); asserteq!(b"ab", groups1.group(0).unwrap()); asserteq!(0..2, groups1.grouprange(0).unwrap());
let groups2 = re.matchall(b"c").unwrap(); asserteq!(None, groups2.group(0)); asserteq!(None, groups2.grouprange(0));
// groups2.group(1); // panics ```
regex!(r"[a-z][0-9]")
match_all
fn, for use on untrusted data.
Make it the default.Repeat
and other types.Cargo.toml
and bump version number../release.sh
License: Apache-2.0