Expand description
fast-glob is a high-performance glob matching crate for Rust, originally forked from devongovett/glob-match.
This crate provides efficient glob pattern matching with support for multi-pattern matching and brace expansion.
§Key Features
- Up to 60% performance improvement.
- Support for more complex and efficient brace expansion.
- Fixed matching issues with wildcard and globstar
glob-match/issues#9.
§Examples
use fast_glob::glob_match;
let glob = "some/**/n*d[k-m]e?txt";
let path = "some/a/bigger/path/to/the/crazy/needle.txt";
assert!(glob_match(glob, path));§Validation
glob_match does not report invalid patterns — an unclosed { or [,
a trailing \, or brace expansions nested deeper than 10 levels have an
unspecified result (typically no match). This is a deliberate performance
trade-off: there is no compile step, and the pattern is interpreted lazily
while matching, so reliably detecting a malformed pattern would require an
extra scan on every call. Validation is instead a separate, one-time step —
use validate to reject such patterns with a descriptive Error:
use fast_glob::{validate, Error, ErrorKind};
assert!(validate("some/**/n*d[k-m]e?txt").is_ok());
assert_eq!(
validate("src/**/*.{js,ts"),
Err(Error { kind: ErrorKind::UnclosedBrace, index: 9 })
);§Syntax
fast-glob supports the following glob pattern syntax:
| Syntax | Meaning |
|---|---|
? | Matches any single character. |
* | Matches zero or more characters, except for path separators (e.g., /). |
** | Matches zero or more characters, including path separators. Must match a complete path segment (i.e., followed by a / or the end of the pattern). |
[ab] | Matches one of the characters contained in the brackets. Character ranges, e.g., [a-z], are also supported. Use [!ab] or [^ab] to match any character except those contained in the brackets. |
{a,b} | Matches one of the patterns contained in the braces. Any of the wildcard characters can be used in the sub-patterns. Braces may be nested up to 10 levels deep. |
! | When at the start of the glob, this negates the result. Multiple ! characters negate the glob multiple times. |
\ | A backslash character may be used to escape any of the above special characters. |
For detailed usage and API reference, refer to the specific function and struct documentation.
For any issues or contributions, please visit the GitHub repository.
Structs§
Enums§
Functions§
- glob_
match - Performs glob pattern matching for
globagainstpath. - validate
- Checks that
globis a valid pattern.