alexnask/ctregex.zig
Compile time regular expressions in zig
Generating fast code since 2020
(:<name>...)
support)|
, *
, +
, ?
, (:?...)
, [...]
, [^...]
, {N}
, {min,}
, {min,max}
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