| 1 | # wildmatch |
| 2 | |
| 3 | [](https://github.com/becheran/wildmatch/actions?workflow=Build) |
| 4 | [](https://docs.rs/wildmatch/latest/wildmatch/) |
| 5 | [](https://crates.io/crates/wildmatch) |
| 6 | [](https://crates.io/crates/wildmatch) |
| 7 | [](https://opensource.org/license/MIT) |
| 8 | [](https://app.codecov.io/gh/becheran/wildmatch) |
| 9 | |
| 10 | Match strings against a simple wildcard pattern. Tests a wildcard pattern `p` against an input string `s`. Returns true only when `p` matches the entirety of `s`. |
| 11 | |
| 12 | See also the example described on [wikipedia](https://en.wikipedia.org/wiki/Matching_wildcards) for matching wildcards. |
| 13 | |
| 14 | - `?` matches exactly one occurrence of any character. |
| 15 | - `*` matches arbitrary many (including zero) occurrences of any character. |
| 16 | - No escape characters are defined. |
| 17 | |
| 18 | Can also be used with a [custom match pattern](https://docs.rs/wildmatch/latest/wildmatch/struct.WildMatchPattern.html) to define own wildcard patterns for single and multi-character matching. |
| 19 | |
| 20 | For example the pattern `ca?` will match `cat` or `car`. The pattern `https://*` will match all https urls, such as `https://google.de` or `https://github.com/becheran/wildmatch`. |
| 21 | |
| 22 | The following table shows a performance benchmarks between wildmatch, [regex](https://crates.io/crates/regex),[glob](https://docs.rs/glob/0.3.0/glob/struct.Pattern.html), and the [regex_lite](https://github.com/rust-lang/regex/tree/master/regex-lite) libraries: |
| 23 | |
| 24 | | Benchmark | wildmatch | regex | glob | regex_lite |
| 25 | | ---- | ------------: | ---------: | -------------: | ---------: |
| 26 | | compiling/text | **462 ns** | 39,714 ns | 1,470 ns | 13,210 ns |
| 27 | | compiling/complex | 190 ns | 153,830 ns | 238 ns | **60 ns** |
| 28 | | matching/text | **186 ns** | 4,065 ns | 456 ns | 6,097 ns |
| 29 | | matching/complex | **310 ns** | 16,085 ns | 1,426 ns | 3,773 ns |
| 30 | |
| 31 | The library only depends on the rust [`stdlib`](https://doc.rust-lang.org/std/). |
| 32 | |
| 33 | See the [documentation](https://docs.rs/wildmatch/latest/wildmatch/) for usage and more examples. |