| Crates.io | safe-regex |
| lib.rs | safe-regex |
| version | 0.3.0 |
| created_at | 2021-02-25 10:07:23.738649+00 |
| updated_at | 2024-04-15 19:28:00.893136+00 |
| description | Safe regular expression library |
| homepage | |
| repository | https://gitlab.com/leonhard-llc/safe-regex-rs |
| max_upload_size | |
| id | 360306 |
| size | 118,820 |
A safe regular expression library.
forbid(unsafe_code).abc[-ab0-9], [^ab]a?, a*, a+, a{1}, a{1,}, a{,1}, a{1,2}, a{,}a|b|ca(bc)?a(?:bc)?no_std, by omitting the default "std" featureOnly works on byte slices, not strings.
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 | 20 | find date time .*([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+).* |
| 1 | 0.75 | parse date time ([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+) |
| 1 | 50 | check PEM Base64 [a-zA-Z0-9+/]{0,64}=* |
| 1 | 20-500 | 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(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.3.0
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex-macro 0.3.0
0/0 0/0 0/0 0/0 0/0 🔒 ├── safe-proc-macro2 1.0.68
0/0 0/0 0/0 0/0 0/0 🔒 │ └── unicode-xid 0.2.4
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex-compiler 0.3.0
0/0 0/0 0/0 0/0 0/0 🔒 ├── safe-proc-macro2 1.0.68
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-quote 1.0.15
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-proc-macro2 1.0.68
0/0 0/0 0/0 0/0 0/0
use safe_regex::{regex, Matcher0};
let matcher: Matcher0<_> =
regex!(br"[ab][0-9]*");
assert!(matcher.is_match(b"a42"));
assert!(!matcher.is_match(b"X"));
use safe_regex::{regex, Matcher3};
let matcher: Matcher3<_> =
regex!(br"([ab])([0-9]*)(suffix)?");
let (prefix, digits, suffix) =
matcher.match_slices(b"a42").unwrap();
assert_eq!(b"a", prefix);
assert_eq!(b"42", digits);
assert_eq!(b"", suffix);
let (prefix_range, digits_r, suffix_r)
= matcher.match_ranges(b"a42").unwrap();
assert_eq!(0..1_usize, prefix_range);
assert_eq!(1..3_usize, digits_r);
assert_eq!(0..0_usize, suffix_r);
assert_match and default std feature.regex! macro invocation sites.no_std. Thank you, Soares Chen! github.com/soareschen gitlab.com/soareschen-informalmatch_all -> match_slices.match_ranges.match_all return typesrc/bin/uncompilable/main.rs.(ab|cd)*.
Idea: Return an MatcherNIter struct that is an iterator that returns MatcherN structs.tests/dfa_single_pass.rs
and tests/nfa_without_capturing.rs.const fn parameters are stable,
make the MatcherN::new functions const.License: Apache-2.0