https://github.com/xcaeser/glob.zig
Fast and reliable glob pattern matching in pure zig.
https://github.com/xcaeser/glob.zig
zig zig-package ziglang
Last synced: about 12 hours ago
JSON representation
Fast and reliable glob pattern matching in pure zig.
- Host: GitHub
- URL: https://github.com/xcaeser/glob.zig
- Owner: xcaeser
- License: mit
- Created: 2025-10-31T18:53:39.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-10-31T18:58:39.000Z (8 months ago)
- Last Synced: 2025-10-31T20:27:18.963Z (8 months ago)
- Topics: zig, zig-package, ziglang
- Language: Zig
- Homepage: https://xcaeser.github.io/glob.zig/
- Size: 7.81 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - xcaeser/glob.zig - Fast and reliable glob pattern matching in pure Zig. (Language Essentials / File Format Processing)
README
# ๐ glob.zig - a powerful glob matcher
Fast and reliable glob pattern matching in pure zig.
[glob.zig reference docs](https://xcaeser.github.io/glob.zig)
[](https://github.com/xcaeser/glob.zig/actions/workflows/main.yml)
[](README.md)
[](LICENSE)
[](https://github.com/xcaeser)
[](https://github.com/xcaeser/glob.zig/releases)
## ๐ Features
- Fast glob pattern matching with `*`, `?`, and character classes `[abc]`, `[a-z]`
- Negation support with `!` prefix
- Pattern validation for common errors
- Multiple pattern matching (`matchAny`, `matchAll`)
- No dependencies, pure Zig
- Comprehensive test suite
## ๐ฆ Installation
```sh
zig fetch --save=glob https://github.com/xcaeser/glob.zig/archive/v0.1.0.tar.gz
```
Add to your `build.zig`:
```zig
const glob_dep = b.dependency("glob", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("glob", glob_dep.module("glob"));
```
## ๐งช Example
```zig
const std = @import("std");
const glob = @import("glob");
pub fn main() !void {
// Simple match
const matches = glob.match("*.zig", "main.zig");
std.debug.print("Matches: {}\n", .{matches}); // true
// Character class
const class_match = glob.match("test_[0-9].txt", "test_5.txt");
std.debug.print("Class match: {}\n", .{class_match}); // true
// Negation
const negated = glob.match("!*.tmp", "file.txt");
std.debug.print("Negated: {}\n", .{negated}); // true
// Multiple patterns
const patterns = &[_][]const u8{ "*.zig", "*.c", "*.h" };
const multi = glob.matchAny(patterns, "main.zig");
std.debug.print("Any match: {}\n", .{multi}); // true
// Validate pattern
glob.validate("[a-z]*") catch |err| {
std.debug.print("Invalid pattern: {}\n", .{err});
return;
};
}
```
## ๐ API
### `match(pattern: []const u8, text: []const u8) bool`
Matches text against a glob pattern.
Supported wildcards:
- `*` โ matches any number of characters
- `?` โ matches any single character
- `[abc]` โ matches one character from the set
- `[a-z]` โ matches one character from the range
- `!` โ negates the pattern (must be first character)
### `validate(pattern: []const u8) !void`
Validates a pattern for syntax errors.
### `matchAny(patterns: []const []const u8, text: []const u8) bool`
Returns true if text matches any of the patterns.
### `matchAll(patterns: []const []const u8, text: []const u8) bool`
Returns true if text matches all of the patterns.
## ๐ License
MIT. See [LICENSE](LICENSE). Contributions welcome.