Skip to content

Scythe-Technology/czrex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

czrex

Simple zig wrapper for the C++ regex library

Example

  • Regex
    const std = @import("std");
    const regex = @import("czrex");
    
    pub fn main() !void {
        const allocator = std.heap.page_allocator;
    
        var re = try regex.Regex.compile(allocator, "a(b+)", null);
        defer re.deinit();
    
        if (try re.match("abbbb")) |match| {
            defer match.deinit();
            const groups = match.groups;
            std.debug.print("'{s}' at index: {}\n", .{ groups[0].slice, groups[0].index });
            std.debug.print("'{s}' at index: {}\n", .{ groups[1].slice, groups[1].index });
        }
    }
  • Wide Regex (Unicode)
    const std = @import("std");
    const regex = @import("czrex");
    
    pub fn main() !void {
        const allocator = std.heap.page_allocator;
    
        var re = try regex.WRegex.compile(allocator, "a(🍕+)", null);
        defer re.deinit();
    
        if (try re.match("a🍕🍕🍕🍕")) |match| {
            defer match.deinit();
            const groups = match.groups;
            std.debug.print("'{s}' at index: {}\n", .{ groups[0].slice, groups[0].index });
            std.debug.print("'{s}' at index: {}\n", .{ groups[1].slice, groups[1].index });
        }
    }

About

Simple Zig wrapper for C++ Regex

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published