A zero-dependency glob pattern matcher for HolyPHP supporting *, ?, **, [abc] / [!abc] / [a-z] character classes, {a,b} brace alternation, and \ escaping for file paths and strings.
bundled — works offlinezero dependencieswildcardpattern
Matches zero or more directory segments (e.g. **/a.txt matches a.txt and x/y/a.txt)
[abc]
Matches any single character in the set (except /)
[a-z]
Matches any single character in the ASCII range (except /)
[!abc] / [^abc]
Matches any single character NOT in the set (except /)
{a,b,c}
Brace alternation (supports nesting and multiple groups)
\x
Escapes metacharacter x to match it literally
API Reference
glob_match(string $pattern, string $text): bool
Returns true if $text matches $pattern, otherwise false. Throws an Exception if $pattern has invalid syntax.
glob_filter(string $pattern, array $items): array
Filters $items (an array of strings) and returns a new re-indexed array containing only the elements that match $pattern. Validates $pattern even when $items is empty, and throws an Exception if any element in $items is not a string.
glob_expand(string $pattern): array
Expands {a,b} brace alternations in $pattern into an array of concrete glob patterns. Validates syntax and throws an Exception on malformed patterns.
glob_escape(string $text): string
Escapes all glob metacharacters (*, ?, [, ], {, }, \, ,) in $text so it can be matched literally.
glob_validate(string $pattern): bool
Validates $pattern syntax. Returns true if valid, or throws an Exception with a descriptive message if invalid.
Error Handling
All syntax and input errors throw Exception with a glob: prefix:
Unclosed character class: glob: unclosed character class '[' in pattern: [abc
Unclosed brace: glob: unclosed brace '{' in pattern: {a,b
Unmatched closing brace: glob: unmatched closing brace '}' at index 3 in pattern: foo}
Trailing escape: glob: trailing escape '\' at end of pattern: foo\
Invalid character range: glob: invalid character range 'z-a' in pattern: [z-a]
Non-string item in glob_filter: glob: glob_filter expects all items to be strings, got non-string at index 1
Examples
01Quick start
Bundled with the compiler — import "glob"; works offline in any file, or add it to a project with hphp install glob.