Crate wildmatch

source ·
Expand description

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.

See also the example described on wikipedia for matching wildcards.

No escape characters are defined.

  • ? matches exactly one occurrence of any character.
  • * matches arbitrary many (including zero) occurrences of any character.

Examples matching wildcards:

assert!(WildMatch::new("cat").matches("cat"));
assert!(WildMatch::new("*cat*").matches("dog_cat_dog"));
assert!(WildMatch::new("c?t").matches("cat"));
assert!(WildMatch::new("c?t").matches("cot"));

Examples not matching wildcards:

assert!(!WildMatch::new("dog").matches("cat"));
assert!(!WildMatch::new("*d").matches("cat"));
assert!(!WildMatch::new("????").matches("cat"));
assert!(!WildMatch::new("?").matches("cat"));

You can specify custom char values for the single and multi-character wildcards. For example, to use % as the multi-character wildcard and _ as the single-character wildcard:

assert!(WildMatchPattern::<'%', '_'>::new("%cat%").matches("dog_cat_dog"));

Structs§

Type Aliases§

  • A wildcard matcher using * as the multi-character wildcard and ? as the single-character wildcard.