simplematch is a Rust library that provides fast extended wildcard pattern
matching for strings and bytes with a simple and intuitive API.
Supports the basic wildcards * (matches any sequence of characters), ?
(matches a single character). Optionally enable escaping \ of special
characters or enable character classes [...]. Character classes can be negated
[!...] and contain ranges [a-zA-Z].
- Optimized for performance
- Simple API consisting of two functions
dowildanddowild_withwith custom pattern matchingOptions - Customizable wildcard characters and matching options like
case-insensitive #![no_std]compatible (when thestdfeature is disabled)- Fully documented on docs.rs
The basic function dowild:
use simplematch::dowild;
assert_eq!(dowild("foo*".as_bytes(), "foobar".as_bytes()), true);
assert_eq!(dowild("foo?".as_bytes(), "fooa".as_bytes()), true)or more conveniently, bring the DoWild trait in scope to match directly
on strings (and bytes) without performance loss:
use simplematch::DoWild;
assert_eq!("foo*".dowild("foobar"), true);Use dowild_with with Options to customize the pattern matching:
use simplematch::{dowild_with, Options, DoWild};
let options = Options::default()
.case_insensitive(true)
.wildcard_any_with(b'%');
assert_eq!(
"foo%".dowild_with("FOObar", options),
true
);Add simplematch to your Cargo.toml:
[dependencies]
simplematch = "0.3.1"Or use cargo add:
cargo add simplematch@0.3.1The benchmarks below show the average instruction counts of each function for a given pattern and haystack. The haystacks and patterns are random valid utf-8 strings each with variable length.
| library/haystack length (samples) |
128(100) |
512(100) |
1000(100) |
10000(100) |
50000(100) |
100000(100) |
|---|---|---|---|---|---|---|
| simplematch::dowild | 1694 |
4937 |
7331 |
82397 |
401193 |
706097 |
| simplematch::dowild_with | 2215 |
6493 |
9606 |
107840 |
518858 |
921040 |
| regex::bytes::Regex::is_match (precompiled) |
199782 |
255366 |
268337 |
405869 |
742161 |
1061864 |
| wildcard::Wildcard::is_match | 2937 |
6347 |
13313 |
134660 |
530098 |
1053973 |
| wildmatch::Wildmatch::matches | 4929 |
13021 |
22972 |
232901 |
1105726 |
2122128 |
To be able to run these benchmarks, you need
iai-callgrind installed. Then run
the benchmarks from above with cargo bench -p benchmarks --bench random.
simplematch is dual licensed under the Apache 2.0 license and the MIT license
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as in License, without any additional terms or conditions.