simplematch
simplematch is a Rust library that provides fast extended wildcard pattern
matching for strings and bytes with a simple and intuitive API.
Features
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
Examples
The basic function dowild:
use dowild;
assert_eq!;
assert_eq!
or more conveniently, bring the DoWild trait in scope to match directly
on strings (and bytes) without performance loss:
use DoWild;
assert_eq!;
Use dowild_with with Options to customize the pattern matching:
use ;
let options = default
.case_insensitive
.wildcard_any_with;
assert_eq!;
Installation
Add simplematch to your Cargo.toml:
[]
= "0.3.1"
Or use cargo add:
Benchmarks
The 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.
License
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.