Match file paths against glob patterns — supports *, **, ?, character classes, brace expansion, and negation.
dotnet add package Philiprehberger.GlobMatcherMatch file paths against glob patterns — supports *, **, ?, character classes, brace expansion, and negation.
dotnet add package Philiprehberger.GlobMatcher
using Philiprehberger.GlobMatcher;
var matched = Glob.IsMatch("src/**/*.cs", "src/Models/User.cs");
// true
using Philiprehberger.GlobMatcher;
Glob.IsMatch("*.txt", "readme.txt"); // true
Glob.IsMatch("src/*.cs", "src/Program.cs"); // true
Glob.IsMatch("**/*.json", "a/b/c.json"); // true
Glob.IsMatch("file?.log", "file1.log"); // true
Glob.IsMatch("[abc].txt", "b.txt"); // true
using Philiprehberger.GlobMatcher;
var files = new[] { "app.cs", "app.js", "lib.cs", "readme.md" };
var csFiles = Glob.Match("*.cs", files);
// ["app.cs", "lib.cs"]
var filtered = Glob.Filter("*.cs", files);
// ["app.cs", "lib.cs"] (alias for Match)
Pre-compile a pattern for efficient reuse across multiple match operations:
using Philiprehberger.GlobMatcher;
var compiled = Glob.Compile("src/**/*.cs");
compiled.IsMatch("src/Models/User.cs"); // true
compiled.IsMatch("test/foo.cs"); // false
var files = new[] { "src/App.cs", "src/readme.md", "src/Lib.cs" };
var csFiles = compiled.Filter(files);
// ["src/App.cs", "src/Lib.cs"]
With options:
var compiled = Glob.Compile("*.CS", new GlobOptions(CaseSensitive: false));
compiled.IsMatch("App.cs"); // true
using Philiprehberger.GlobMatcher;
Glob.IsMatch("!*.log", "data.csv"); // true
Glob.IsMatch("!*.log", "error.log"); // false
Glob| Method | Description |
|---|---|
IsMatch(string pattern, string path) | Test if a path matches a glob pattern |
IsMatch(string pattern, string path, GlobOptions options) | Test with custom options |
Match(string pattern, IEnumerable<string> paths) | Return all matching paths |
Filter(string pattern, IEnumerable<string> paths) | Alias for Match |
Compile(string pattern, GlobOptions? options) | Pre-compile a pattern for reuse |
CompiledGlob| Method | Description |
|---|---|
IsMatch(string path) | Test if a path matches the compiled pattern |
Filter(IEnumerable<string> paths) | Return all matching paths |
Pattern | The original pattern string |
GlobOptions| Property | Type | Default | Description |
|---|---|---|---|
CaseSensitive | bool | true | Whether matching is case-sensitive |
PathSeparator | char | '/' | Path separator character |
dotnet build src/Philiprehberger.GlobMatcher.csproj --configuration Release
If you find this project useful: