-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Hi,
I have such a code snippet,
const std = @import("std");
const regex = @import("regex");
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
var pattern = try regex.Regex.compile(arena.child_allocator, "\\$t\\((.*)\\)");
const target = "$t(common.hello) abc $t(common.name)";
try search(arena.child_allocator, target, pattern);
pattern = try regex.Regex.compile(arena.child_allocator, "\\$t\\((.*?)\\)");
try search(arena.child_allocator, target, pattern);
}
fn search(allocator: std.mem.Allocator, target: []const u8, re: regex.Regex) !void {
const matches = try re.findAll(allocator, target);
for (matches) |m| {
for (m.captures) |cap| {
std.debug.print("{s}\n", .{cap});
}
}
}and its output is as below
zig-out/bin/translator
common.hello) abc $t(common.nameIt seems that the question mark makes it find nothing.
And what I expect should be "common.hello" and "common.name" (without quote mark).
Is this a issue of zig-regex?
Yes, it does resolve the issue to replace the pattern "\$t\((.)\)" with "\$t\((\S)\)", however it cannot handle "$t(common.hello)$t(common.name)"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels