Fast and reliable glob pattern matching in pure zig.
- 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
zig fetch --save=glob https://github.com/xcaeser/glob.zig/archive/v0.1.0.tar.gzAdd to your build.zig:
const glob_dep = b.dependency("glob", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("glob", glob_dep.module("glob"));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;
};
}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)
Validates a pattern for syntax errors.
Returns true if text matches any of the patterns.
Returns true if text matches all of the patterns.
MIT. See LICENSE. Contributions welcome.