4 releases (breaking)

0.3.0 Nov 14, 2024
0.2.0 Jul 9, 2024
0.1.0 Jul 3, 2024
0.0.0-pre May 24, 2024

#297 in Text processing

Download history 145706/week @ 2025-10-18 162135/week @ 2025-10-25 161140/week @ 2025-11-01 168033/week @ 2025-11-08 169648/week @ 2025-11-15 98431/week @ 2025-11-22 66659/week @ 2025-11-29 48000/week @ 2025-12-06 53393/week @ 2025-12-13 31540/week @ 2025-12-20 27727/week @ 2025-12-27 63233/week @ 2026-01-03 69348/week @ 2026-01-10 71249/week @ 2026-01-17 105204/week @ 2026-01-24 124546/week @ 2026-01-31

381,502 downloads per month
Used in 18 crates (7 directly)

Apache-2.0

56KB
1K SLoC

Build Status Dependency status crates.io Downloads Github stars Documentation License

wildcard

wildcard is a rust crate for wildcard matching.

Here's how to use it:

let wildcard = Wildcard::new("*foo?*bar".as_bytes()).unwrap();

assert!(wildcard.is_match("fooofooobar".as_bytes()));

Special characters can be escaped to represent their literal symbol:

let wildcard = Wildcard::new(r"\*\?".as_bytes()).unwrap();

assert!(!wildcard.is_match("ab".as_bytes()));
assert!(wildcard.is_match("*?".as_bytes()));

You can also capture the substring that matched the metasymbols of the wildcard:

let wildcard = Wildcard::new("* is a * style?".as_bytes()).unwrap();

let captures: Vec<&[u8]> = wildcard.captures("Lambic is a beer style!".as_bytes()).unwrap();

assert_eq!(captures, ["Lambic".as_bytes(), "beer".as_bytes(), "!".as_bytes()]);

String matching

For performance reasons wildcard does not match directly on strings, but it supports matching on slices of chars:

let p = "*foo?*bar".chars().collect::<Vec<_>>();
let wildcard = Wildcard::new(&p).unwrap();

assert!(wildcard.is_match(&"fooofooobar".chars().collect::<Vec<_>>()));

Matching customization

With wildcard you can configure these properties of a wildcard:

  1. Configure the symbols for the metasymbols * and ? as well as the escape symbol.
  2. Support for the metasymbol ? can be disabled.
  3. Support for escaping can be disabled.
  4. Support for case-insensitive matching.

Dependencies

~150–550KB
~13K SLoC