Crates.io | wildcard |
lib.rs | wildcard |
version | 0.2.0 |
source | src |
created_at | 2024-05-24 09:51:10.320511 |
updated_at | 2024-07-09 09:56:27.167268 |
description | Wildcard matching |
homepage | https://github.com/cloudflare/wildcard |
repository | https://github.com/cloudflare/wildcard |
max_upload_size | |
id | 1250866 |
size | 94,689 |
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()]);
With wildcard
you can configure these properties of a wildcard:
*
and ?
as well as the escape symbol.?
can be disabled.