Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/francisrstokes/zigex
A regular expression engine written in Zig
https://github.com/francisrstokes/zigex
Last synced: 14 days ago
JSON representation
A regular expression engine written in Zig
- Host: GitHub
- URL: https://github.com/francisrstokes/zigex
- Owner: francisrstokes
- Created: 2023-11-18T21:32:41.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2023-11-30T21:41:06.000Z (12 months ago)
- Last Synced: 2024-04-16T01:08:12.346Z (7 months ago)
- Language: Zig
- Size: 123 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# zigex
`zigex` is a regular expression library for [Zig](https://github.com/ziglang/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:
```bash
git submodule add https://github.com/francisrstokes/zigex libs/zigex
```2. Add the library as a module to your projects `build.zig`:
```zig
exe.addAnonymousModule("zigex", .{
.source_file = .{ .path = "libs/zigex/src/regex.zig" },
});
```3. Import in your project source:
```zig
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}: \n", .{i});
}
}
```4. Build and run
```bash
$ zig build
$ ./zig-out/bin/your-appMatch: aHelloWorld1y
Group 1: "aHelloWorld1" index=0
Group 2: "y" index=12
```