simplematch

Crates.iosimplematch
lib.rssimplematch
version0.3.1
created_at2025-09-14 14:40:42.98461+00
updated_at2025-09-20 06:01:37.052188+00
descriptionFast wildcard pattern matching for strings and bytes with a simple api
homepagehttps://github.com/gamma0987/simplematch
repositoryhttps://github.com/gamma0987/simplematch
max_upload_size
id1838863
size146,496
(gamma0987)

documentation

README

simplematch

Released API Docs | Changelog

GitHub branch checks state Coverage Crates.io docs.rs

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 dowild and dowild_with with custom pattern matching Options
  • Customizable wildcard characters and matching options like case-insensitive
  • #![no_std] compatible (when the std feature is disabled)
  • Fully documented on docs.rs

Examples

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
);

Installation

Add simplematch to your Cargo.toml:

[dependencies]
simplematch = "0.3.1"

Or use cargo add:

cargo add simplematch@0.3.1

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.

Commit count: 71

cargo fmt