Skip to content

francisrstokes/zigex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zigex

zigex is a regular expression library for Zig.

⚠️ Warning ⚠️: This is not a production-ready library. It is incomplete and minimally documented.

Installation (git submodule)

  1. Add the repo as a submodule to your project. Place it libs/ at the root of your project:
git submodule add https://github.com/francisrstokes/zigex libs/zigex
  1. Add the library as a module to your projects build.zig:
exe.addAnonymousModule("zigex", .{
    .source_file = .{ .path = "libs/zigex/src/regex.zig" },
});
  1. Import in your project source:
const zigex = @import("zigex");

...

var re = try zigex.Regex.init(your_allocator, "(a.+\\d)?(x|y)$", .{});
defer re.deinit();

var match = try re.match("aHelloWorld1y") orelse {
    std.debug.print("No match\n", .{});
    return;
};
defer match.deinit();

std.debug.print("Match: \"{s}\" index={d}\n", .{match.match.value, match.match.index});

var groups = try match.get_groups(your_allocator);
defer groups.deinit();

for (groups.items, 1..) |group, i| {
    if (group) |g| {
        std.debug.print("Group {d}: \"{s}\" index={d}\n", .{ i, g.value, g.index });
    } else {
        std.debug.print("Group {d}: <null>\n", .{i});
    }
}
  1. Build and run
$ zig build
$ ./zig-out/bin/your-app

Match: aHelloWorld1y
Group 1: "aHelloWorld1" index=0
Group 2: "y" index=12

About

A regular expression engine written in Zig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages