alexnask/ctregex.zig
Compile time regular expressions in zig
{ "createdAt": "2020-06-22T22:19:33Z", "defaultBranch": "master", "description": "Compile time regular expressions in zig", "fullName": "alexnask/ctregex.zig", "homepage": null, "language": "Zig", "name": "ctregex.zig", "pushedAt": "2023-08-27T20:50:16Z", "stargazersCount": 151, "topics": [ "compile-time", "regex", "zig", "zig-library", "zig-package" ], "updatedAt": "2025-11-07T07:28:01Z", "url": "https://github.com/alexnask/ctregex.zig"}Zig compile time regular expressions
Section titled “Zig compile time regular expressions”Generating fast code since 2020
Features
Section titled “Features”- Comptime regular expression compilation
- Comptime and runtime matching
- UTF8, UTF16le, ASCII, codepoint array support
- Captures (with named
(:<name>...)support) |,*,+,?,(:?...),[...],[^...],{N},{min,},{min,max}- ‘\d’, ‘\s’ character classes
- Faster generated code using DFAs when possible
- search, findAll, etc.
- More character classes
- More features (backreferences etc.)
Example
Section titled “Example”test "runtime matching" { @setEvalBranchQuota(1250); // The encoding is utf8 by default, you can use .ascii, .utf16le, .codepoint here instead. if (try match("(?<test>def|abc)([😇ω])+", .{.encoding = .utf8}, "abc😇ωωωωω")) |res| { std.debug.warn("Test: {}, 1: {}\n", .{ res.capture("test"), res.captures[1] }); }}
test "comptime matching" { @setEvalBranchQuota(2700); if (comptime try match("(?<test>def|abc)([😇ω])+", .{}, "abc😇ωωωωω")) |res| { @compileError("Test: " ++ res.capture("test").? ++ ", 1: " ++ res.captures[1].?); }}See tests.zig for more examples.
Small benchmark with ctregex, PCRE2