https://github.com/cloudflare/wildcard
Wildcard matching
https://github.com/cloudflare/wildcard
text-processing wildcard
Last synced: 14 days ago
JSON representation
Wildcard matching
- Host: GitHub
- URL: https://github.com/cloudflare/wildcard
- Owner: cloudflare
- License: apache-2.0
- Created: 2024-07-01T14:27:53.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-04T21:24:01.000Z (5 months ago)
- Last Synced: 2025-04-15T02:12:56.445Z (14 days ago)
- Topics: text-processing, wildcard
- Language: Rust
- Homepage:
- Size: 45.7 MB
- Stars: 192
- Watchers: 9
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/cloudflare/wildcard/actions?query=workflow%3ACI)
[](https://deps.rs/repo/github/cloudflare/wildcard)
[](https://crates.io/crates/wildcard)
[](https://crates.io/crates/wildcard)
[](https://github.com/cloudflare/wildcard/stargazers)
[](https://docs.rs/wildcard/)
[](./LICENSE)# `wildcard`
`wildcard` is a rust crate for wildcard matching.
Here's how to use it:
```rust
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:
```rust
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:
```rust
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 `char`s:```rust
let p = "*foo?*bar".chars().collect::>();
let wildcard = Wildcard::new(&p).unwrap();assert!(wildcard.is_match(&"fooofooobar".chars().collect::>()));
```## 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.