From 0423e315dfeaa5af48d2186a8f0997e1904f3da9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 01:41:06 -0300 Subject: $ may end any alternative in a pattern, not only the last mvzr refuses $ anywhere but at the very end, so /h$|zz/ and Edit ,x/r$|pi/ were bad patterns while /zz|h$/ worked. Its matcher already ends an alternative at .end, so a build-time patch, anchor-checked like the group one, lets $ stand before | and ). The upstream report is in docs/mvzr-group-backtrack.md. Co-Authored-By: Claude Opus 5.5 --- src/regexp.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/regexp.zig') diff --git a/src/regexp.zig b/src/regexp.zig index 97e3dc91..64e1d75a 100644 --- a/src/regexp.zig +++ b/src/regexp.zig @@ -258,3 +258,20 @@ test "a repeat inside a group gives back to what follows the group" { try std.testing.expectEqual(c.end, m.end); } } + +test "`$` may end any alternative, not only the last" { + const Case = struct { pat: []const u8, text: []const u8, start: usize, end: usize }; + for ([_]Case{ + .{ .pat = "h$|zz", .text = "xh", .start = 1, .end = 2 }, + .{ .pat = "zz|h$", .text = "xh", .start = 1, .end = 2 }, + .{ .pat = "h$|zz", .text = "hx zz", .start = 3, .end = 5 }, + .{ .pat = "(h$|zz)", .text = "xh", .start = 1, .end = 2 }, + }) |c| { + var rx = try Regex.compile(c.pat); + const m = (try rx.find(c.text, 0, c.text.len, c.text.len)).?; + try std.testing.expectEqual(c.start, m.start); + try std.testing.expectEqual(c.end, m.end); + } + var only = try Regex.compile("h$|zz"); + try std.testing.expectEqual(null, try only.find("hx", 0, 2, 2)); +} -- cgit v1.3