safe-regex-0.1.0 has been yanked.
safe-regex
A safe regular expression library.
Features
forbid(unsafe_code)- Good test coverage (??%) - TODO(mleonhard) Update.
- Checks input in a single pass.
Runtime and memory usage are both
O(n * r * 2^g)wherenis the length of the data to checkris the length of the regexgis the number of capturing groups in the regex TODO(mleonhard) Confirm this with a benchmark.
- Rust compiler checks and optimizes the matcher
- Supports basic regular expression syntax:
- Any byte:
. - Sequences:
abc - Classes:
[-ab0-9],[^ab] - Repetition:
a?,a*,a+,a{1},a{1,},a{,1},a{1,2},a{,} - Alternates:
a|b|c - Capturing groups:
a(b*)?
- Any byte:
Limitations
- Only works on byte slices, not strings.
- Allocates. Uses
std::collections::HashSetduring matching.
Alternatives
regex- Mature & Popular
- Maintained by the core Rust language developers
- Contains
unsafecode.
pcre2- Uses PCRE library which is written in unsafe C.
regular-expression- No documentation
rec
Cargo Geiger Safety Report
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(unsafe_code)]
❓ = No `unsafe` usage found, missing #![forbid(unsafe_code)]
☢️ = `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
Examples
use ;
let re: = regex!;
assert_eq!;
assert_eq!;
let groups1 = re.match_all.unwrap;
assert_eq!;
assert_eq!;
let groups2 = re.match_all.unwrap;
assert_eq!;
assert_eq!;
// groups2.group(1); // panics
Changelog
- v0.1.0 - First published version
TO DO
- DONE - Read about regular expressions
- DONE - Read about NFAs, https://swtch.com/~rsc/regexp/
- DONE - Design API
- DONE - Implement
- DONE - Add integration tests
- DONE - Add macro,
regex!(r"[a-z][0-9]") - Add fuzzing tests
- Add common character classes: whitespace, letters, punctuation, etc.
- Match strings
TO DO
- Add a memory-limited
match_allfn, for use on untrusted data. Make it the default. - Once const generics
are stable, use the feature to simplify
Repeatand other types.
Release Process
- Edit
Cargo.tomland bump version number. - Run
./release.sh
License: Apache-2.0