{"id":51228789,"url":"https://github.com/zoptia/zoptia0regex","last_synced_at":"2026-07-17T00:01:06.146Z","repository":{"id":367386874,"uuid":"1280024888","full_name":"zoptia/zoptia0regex","owner":"zoptia","description":"A regular-expression (regex) library for Zig — a faithful, linear-time port of Go's regexp (RE2): proven byte-for-byte identical to Go across 30k differential tests, and ~11% faster.","archived":false,"fork":false,"pushed_at":"2026-07-12T05:16:50.000Z","size":735,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-12T05:18:55.196Z","etag":null,"topics":["golang","nfa","re2","redos","regex","regex-engine","regexp","regular-expression","zig","zig-library","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoptia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-25T07:48:39.000Z","updated_at":"2026-07-12T05:16:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zoptia/zoptia0regex","commit_stats":null,"previous_names":["zoptia/zoptia0regex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zoptia/zoptia0regex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoptia%2Fzoptia0regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoptia%2Fzoptia0regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoptia%2Fzoptia0regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoptia%2Fzoptia0regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoptia","download_url":"https://codeload.github.com/zoptia/zoptia0regex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoptia%2Fzoptia0regex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35561864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-16T02:00:06.687Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","nfa","re2","redos","regex","regex-engine","regexp","regular-expression","zig","zig-library","zig-package"],"created_at":"2026-06-28T14:00:23.332Z","updated_at":"2026-07-17T00:01:06.141Z","avatar_url":"https://github.com/zoptia.png","language":"Zig","funding_links":[],"categories":["Language Essentials"],"sub_categories":["File Format Processing"],"readme":"\u003cdiv align=\"center\"\u003e\n\n# zoptia0regex\n\n### Go's `regexp`, faithfully replicated in Zig — and faster.\n\nA **regular-expression (regex) library for Zig** — a high-fidelity port of the\nRE2 engine, with a linear-time guarantee and **~30,000 tests proving\nbyte-for-byte parity with Go**.\n\n[![CI](https://github.com/zoptia/zoptia0regex/actions/workflows/ci.yml/badge.svg)](https://github.com/zoptia/zoptia0regex/actions)\n[![Zig](https://img.shields.io/badge/Zig-0.16-f7a41d?logo=zig\u0026logoColor=white)](https://ziglang.org/)\n[![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)\n\n\u003c/div\u003e\n\n---\n\n## ⚡ Faster than Go. Identical to Go. Provably.\n\nHead-to-head against Go's standard-library `regexp` — same patterns, same\ninputs, same 256 KB corpus, same calibration, Zig built `ReleaseFast` —\n**zoptia0regex is ~36% faster on average** and compiles patterns **~1.5×\nfaster**. And it doesn't trade correctness for speed: ~30,000 differential tests\nprove its output is **byte-for-byte identical to Go's**.\n\nNot \"inspired by.\" **Proven identical.**\n\n- 🚀 **Faster than Go at matching.** Geometric mean across 20 workloads:\n  **0.64×** Go's time. Anchored \"validation\" patterns hit the one-pass engine\n  and fly — up to **~2× faster** — and a SIMD first-byte prefilter Go doesn't\n  have runs unanchored `(?i)` and `\\d`-led scans at **4–5× Go's speed**.\n- 🛡️ **Linear-time. ReDoS-proof.** Thompson NFA simulation means no catastrophic\n  backtracking, ever. A pattern like `(a+)+` that hangs PCRE, JS, and Python\n  runs in linear time here.\n- ✅ **Proven identical to Go.** ~30,000 differential cases run the *real* Go\n  `regexp` and this engine on the same inputs and require identical results.\n  **Zero mismatches. Zero leaks.** The fidelity isn't a claim — it's enforced by\n  the suite on every push.\n- 🌍 **Unicode-correct.** `(?i)` case folding uses tables generated directly from\n  Go's `unicode.SimpleFold` — correct across *all* of Unicode, not just ASCII.\n\n## In a nutshell\n\n```zig\nvar re = try regex.compile(gpa, \"(\\\\w+)@(\\\\w+)\\\\.(\\\\w+)\");\ndefer re.deinit();\n\nconst subs = (try re.findSubmatch(gpa, \"ping me@example.com\")).?;\n// subs =\u003e \"me\" / \"example\" / \"com\"\n```\n\n→ Full install \u0026 API in the **[usage guide](docs/usage.md)**.\n\n## 📊 The benchmark\n\nZig vs Go, same workload, same machine. Lower is faster — `\u003c 1.0×` means Zig\nwins.\n\n| Workload | Engine | Zig / Go |\n|---|---|---|\n| date scan (`\\d{4}-…`) | first-bytes + Pike VM | **0.21×** |\n| `(?i)performance` (unanchored scan) | first-bytes + Pike VM | **0.25×** |\n| `\\d+` | first-bytes + Pike VM | **0.27×** |\n| alternation | first-bytes + Pike VM | **0.36×** |\n| `\\A\\d+\\z` (anchored validation) | one-pass | **0.47×** |\n| `\\A[a-z]+\\z` (anchored validation) | one-pass | **0.48×** |\n| `\\A(?i)performance\\z` | one-pass | **0.62×** |\n| `\\A(...)@(...)\\z` with captures | one-pass | **0.79×** |\n| **Geometric mean (20 workloads)** | — | **0.64×** |\n| Pattern compilation | — | **0.65×** (~1.5× faster) |\n\n**The honest caveat:** there is exactly **one** workload where Go wins — a\nnested-quantifier match on a small input (`(a+)+$`, bitstate engine) at\n**1.09×**, both sides in single-digit microseconds. Everything else is on par\nor faster. Full methodology and the complete table:\n**[BENCHMARKS.md](BENCHMARKS.md)**.\n\n## Why this exists\n\nzoptia0regex is a faithful, high-fidelity replica of Go's standard-library\n`regexp` package — the RE2 design by Russ Cox. It mirrors Go's **leftmost-first**\nmatch semantics (plus **POSIX leftmost-longest**), the same `Find` / `Replace` /\n`Split` / submatch API surface, and the same four-stage pipeline:\n**parse → simplify → compile → execute**. All three of Go's execution engines\nare here — the **one-pass** matcher, the **bitstate backtracker**, and the\n**Pike VM** — plus literal-prefix acceleration, with the engine chosen\nautomatically per pattern.\n\nAll three engines share literal-prefix acceleration (anchored on the prefix's\nrarest byte, with a Rabin-Karp fallback like Go's `bytes.Index`), and the port\nadds a **SIMD first-byte prefilter** Go doesn't have: when a pattern has no\nliteral prefix but can only start with one of ≤ 16 ASCII bytes — a\ncase-insensitive literal, `\\d`, a small class — the unanchored engines skip\nahead with a portable `@Vector` sweep (NEON / SSE2) instead of stepping the\nNFA at every position.\n\nThat's where the speed *and* the fidelity come from. For the full design\nwalkthrough, see **[docs/internals.md](docs/internals.md)**.\n\n## Features\n\n- 🧩 Full Go `regexp/syntax`: literals, alternation, character classes (`[...]`,\n  `[^...]`, ranges, Perl `\\d\\w\\s`, POSIX `[[:alpha:]]`, Unicode `\\p{...}` curated\n  subset), `.`, anchors `^ $ \\A \\z \\b \\B`.\n- 🔁 Quantifiers `* + ? {n,m}`, greedy and non-greedy.\n- 🏷️ Capturing, non-capturing, and named groups; inline flags `(?imsU)`;\n  escapes; `\\Q...\\E`.\n- ⚖️ Two match modes: leftmost-first (Go default) and POSIX leftmost-longest.\n- 🛡️ Linear-time guarantee — immune to ReDoS.\n- ⚡ Allocation-free hot loops: reuse a `Scratch` across matches\n  (`matchScratch`) for zero-allocation steady state, like Go's machine pool.\n- 🌍 Full-Unicode case folding via Go-derived tables.\n- 🚫 Same intentional limits as RE2/Go: **no backreferences, no `\\C`**.\n\n## Install \u0026 use\n\nRequires **Zig 0.16**.\n\n```sh\nzig fetch --save git+https://github.com/zoptia/zoptia0regex\n```\n\n```zig\nconst regex = @import(\"regex\");\n\nvar re = try regex.compile(gpa, \"(\\\\w+)@(\\\\w+)\\\\.(\\\\w+)\");\ndefer re.deinit();\nconst subs = (try re.findSubmatch(gpa, \"ping me@example.com\")).?;\n```\n\nThat's the taste — the **[full install + API guide lives in docs/usage.md](docs/usage.md)**:\nwiring the dependency into `build.zig`, every `Find` / `FindAll` / `Replace` /\n`Split` / submatch variant, the memory model, and POSIX mode.\n\n## Trust \u0026 validation\n\nEvery push runs the **full ~30,000-case differential suite** in CI, across three\ncorpora:\n\n| Corpus | Cases | What it checks |\n|---|---|---|\n| Curated | ~5.9k | Hand-picked edge cases across every feature |\n| Random / fuzz | ~9k | Grammar-generated patterns \u0026 inputs |\n| POSIX leftmost-longest | ~15k | POSIX match semantics |\n\nEach case runs the *real* Go `regexp` and zoptia0regex on the same input and\nrequires **byte-for-byte identical** `FindSubmatchIndex` / `FindAll` /\n`ReplaceAll` / `Split`. Result: **zero mismatches, zero memory leaks** (checked\nunder `std.testing.allocator`). CI stays green.\n\n```sh\nzig build test        # unit + behaviour tests\nzig build difftest    # the full ~30k differential suite (no Go toolchain needed)\nzig build bench       # benchmark vs Go (ReleaseFast)\n```\n\n## License \u0026 acknowledgement\n\nLicensed under **Apache-2.0**.\n\nzoptia0regex is a faithful port of Go's standard-library `regexp` package. Deep\nthanks to **Russ Cox** and the **Go authors** — portions are derived from Go's\nBSD-3-Clause-licensed code, attributed in [NOTICE](NOTICE). Not affiliated with\nGo or Google.\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n**[Usage guide](docs/usage.md)** · **[Internals](docs/internals.md)** ·\n**[Benchmarks](BENCHMARKS.md)** · **[Contributing](CONTRIBUTING.md)**\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoptia%2Fzoptia0regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoptia%2Fzoptia0regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoptia%2Fzoptia0regex/lists"}