Revera

10 min read Original article ↗

By the OneRegex initiative.

One regular expression engine, generated for every language.

Revera is a clean-room implementation of POSIX.1-2024 extended regular expressions. The engine is written once, checked against a formal model in Lean, and generated into native Go, Rust, Zig, C, C++ and TypeScript libraries. A shared conformance suite checks the same matches, errors and resource reports across all six.

  • Machine-checked in Lean 4
  • Bounded heap and work
  • Native APIs, no bindings

main.go

package main

import (
    "fmt"

    "github.com/oneregex/revera/go"
)

func main() {
    re := revera.MustNew(
        `[[:alpha:]]+@[[:alnum:].]+`,
        revera.NoCaptures(),
    )

    // What can one search cost on any input up to 64 KiB?
    c := re.Contract(65536)
    fmt.Println(c.HeapBytes(), c.StackBytes(), c.Steps())

    ok, _ := re.MatchString("write to alice@example.org")
    fmt.Println(ok)
}

Heap bound1158 bytes

Stack estimate6144 bytes

One engine source, generated for

  • Go
  • Rust
  • Zig
  • C
  • C++
  • TypeScript
  • Lean 4 model

The problem

Every regex library speaks its own dialect.

Regular expressions look universal. They are not. The same pattern can match different text, or fail differently, depending on which library runs it.

Regex engines can disagree

Each implementation has its own features and quirks, and nothing guarantees that a pattern accepted by one returns the same result in another. Move a rule between two services written in different languages and its meaning can quietly change.

They sit in the security path

Regexes filter, validate and route untrusted input, and sometimes the pattern itself comes from a user. A mismatch is not a cosmetic bug. It is a bypass, a crash, or a server that stops answering.

The standard still needs choices

POSIX extended regular expressions provide a real specification, updated in POSIX.1-2024. They also leave some behavior undefined, unspecified or implementation-defined. Revera documents those choices and applies them consistently in every generated engine.

What Revera is

One engine, checked once, shipped to every language.

The OneRegex initiative builds precise regex specifications with explicit verification boundaries, then turns them into interoperable libraries. Revera is that idea applied to POSIX.1-2024 extended regular expressions.

A precise, executable specification

The ERE rules are written down twice: as a plain-language specification every engine implements, and as a formal Lean model the engine is checked against. The remaining implementation choices are documented explicitly.

Cross-checked everywhere

Every library comes from the same engine source and is cross-checked on the same corpus: the same matches, the same errors, the same resource reports. The suite compares each rule through every backend.

Resource contracts

Before a search runs, a compiled pattern reports portable heap and work bounds, plus a stack estimate, for any input up to a chosen length. Provision for it, cap it, or reject the pattern before it ever touches a request.

Native, generated libraries

Go, Rust, Zig, C, C++ and TypeScript, each with a hand-written API in the shape that language expects on top of a generated engine. No bindings to a C library. A new language starts from the same checked IR instead of reimplementing regex semantics.

Resource contracts

Know the worst case before you run it.

Ask a compiled pattern for the portable heap and work bounds of one search, plus its stack estimate, on input up to a chosen length. The figures describe the worst case in that model, not a measurement of one run. Size a service around it, reject a pattern that exceeds a budget, or refuse a request before doing any work.

  • Heap: a portable bound on allocation requests, with conservative rounding allowances. Runtime metadata and garbage-collector bookkeeping are outside the model.
  • Stack: an estimate of the deepest call stack, from fixed frame sizes shared by every target.
  • Steps: an upper bound on abstract unit-cost operations, not elapsed time.
  • Bounded even on failure: a search that would exceed the engine's memory capacity returns a capacity error instead of growing without limit.
// Pattern: [[:alpha:]]+@[[:alnum:].]+
// Compiled without captures. Inputs up to 65536 bytes.
c := re.Contract(65536)

c.HeapBytes()   1158        // bytes, whatever the input
c.StackBytes()  6144        // bytes, deepest call stack
c.Steps()       82380034    // abstract operations, at most

// Same pattern, same call, in every language:
// the six libraries report the same three numbers.

These are the actual figures the Go library reports for that pattern. Bounds are conservative on purpose. A pattern whose captures need the general solver can report a heap bound in the tens of gigabytes. An expression proven one-pass reports only the much smaller capture-walk bound. That is the number you cannot rule out, which is exactly what you need to know before accepting the pattern.

How it works

Written once. Checked once. Generated for every language.

Revera is a pipeline, not six hand-written libraries. The engine is written in Vego, a strict subset of Go made for mechanical translation. A compiler exports it as an intermediate representation, and printers turn that one artifact into each target.

Vego source go/*.go A strict Go subset: no imports, no methods, no interfaces, no function values, no generics.

Vego IR revera.vego.json The versioned engine artifact. Every generated engine, and the Lean model, starts from this file.

Lean 4 well formed, checked, bounded Reads the exact IR, proves it well formed, and checks it against the ERE model within the documented scope.

Gothe source itself

Rustengine.rs

Zigengine.zig

Cengine.c

C++engine.cpp

TypeScriptengine.ts

The Lean development reads byte-for-byte copies of the checked-in IR, so the artifact that is proved is the artifact the printers consume. Each target adds a small hand-written runtime and public API, plus the shared embedded locale data.

Idiomatic output

The same engine, native in your language.

Not bindings. Each library is the generated engine plus a small hand-written API in the shape that language expects.

package main

import (
    "fmt"
    "log"

    "github.com/oneregex/revera/go"
)

func main() {
    re, err := revera.New("(abc)([0-9]*)")
    if err != nil {
        log.Fatal(err)
    }
    groups, err := re.FindStringSubmatch("__abc12__")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(groups[1])
}
use revera::Regex;

fn main() -> Result<(), revera::Error> {
    let re = Regex::new("(abc)([0-9]*)")?;
    let caps = re.captures("__abc12__")?.expect("a match");
    println!("{}", &caps[1]);
    Ok(())
}
const std = @import("std");
const revera = @import("revera");

pub fn main(init: std.process.Init) !void {
    var re = try revera.Regex.compile(init.gpa, "(abc)([0-9]*)", .{});
    defer re.deinit();

    var caps = (try re.captures("__abc12__")).?;
    defer caps.deinit();
    std.debug.print("{s}\n", .{caps.get(1).?.text()});
}
#include <stdio.h>
#include <revera/revera.h>

int main(void) {
    const char pattern[] = "(abc)([0-9]*)";
    const char subject[] = "__abc12__";
    revera_error error;
    revera_regex *re = revera_compile(pattern, sizeof(pattern) - 1, NULL, &error);
    if (re == NULL) {
        return 1;
    }

    revera_match groups[3];
    if (!revera_captures(re, subject, sizeof(subject) - 1, groups, 3, &error)) {
        revera_regex_free(re);
        return 1;
    }
    printf("%.*s\n", (int)(groups[1].end - groups[1].start),
           subject + groups[1].start);
    revera_regex_free(re);
}
#include <iostream>
#include <revera/revera.hpp>

int main() {
    revera::Regex re("(abc)([0-9]*)");
    auto caps = re.captures("__abc12__");
    if (!caps || !(*caps)[1]) {
        return 1;
    }
    std::cout << (*caps)[1]->str() << '\n';
}
import { Regex } from "@oneregex/revera";

const re = new Regex("(abc)([0-9]*)");
const caps = re.captures("__abc12__");
if (caps === null) {
    throw new Error("no match");
}
console.log(caps.get(1)?.text);

// every one of them prints: abc

Go
go get github.com/oneregex/revera/go

Rust
cargo add revera

Zig
Use the source package. No public Zig archive is available yet.

C and C++
Build and install the CMake package, then link Revera::C or Revera::CXX.

TypeScript
npm install @oneregex/revera

Correctness and interoperability

Cross-checked across languages. Proved against the specification.

No single mechanism carries the claim. Each layer catches what the others cannot. Phase A is the first matching stage: it scans the subject once and selects the overall match span before Phase B resolves subexpression captures.

One corpus, every backend

The conformance kit runs the same fixed corpus of 90,145 commands, covering matches, errors, replacements, iteration and contract reports, through every generated backend, and compares each answer with the canonical Go engine. Random stress rounds, a fuzz seed pack and sanitizer builds are part of the same run.

A formal ERE model in Lean

The POSIX.1-2024 ERE rules are stated as a Lean definition, written from the standard text and not from any engine. The interpreted engine is checked against that definition on every constrained corpus case, and on an exhaustive sweep of 41,370 small patterns against every short subject, over 1.5 million executions.

Proofs about the shipped artifact

Lean decodes the exact IR files that ship, proves them well formed, and proves universal heap and step bounds for Phase A of the matcher, along with the soundness of the meter that records those costs. The proved file is the checked-in IR consumed by the printers.

The proofs have explicit limits, and the Lean README states each one. The corpus and exhaustive checks are finite, not universal. Non-POSIX locale behavior is outside the model. The link between the proved Phase A properties and the shipped engine covers corpus executions that use Phase A alone. The generated Rust, Zig, C, C++ and TypeScript engines are tied to the proved IR by the conformance corpus, not by a proof of the printers.

Is this just another regex library?

No. Revera is a specification with a formal model, one engine source, and printers. You do not get a hand-ported library per language. You get engines generated from a single artifact that Lean checks against the ERE model, and that a shared corpus cross-checks against each other.

Which regular expression dialect is it?

POSIX.1-2024 extended regular expressions: leftmost-longest matching, bracket expressions with character classes, equivalence classes and collating elements, interval expressions, and the shortest-preferring repetition modifiers that the 2024 revision added. There are no backreferences and no Perl escapes, because the ERE language has none. Revera does not provide Perl-compatible syntax.

What exactly is a resource contract?

For a compiled pattern and a maximum input length, Revera reports an upper bound on heap bytes, an upper bound on abstract work, and an estimate of stack use. The report applies to every subject up to that length. You can read it before running a match and use it to accept, reject or budget a pattern.

Does it use a C library under the hood?

No. Each library is the engine generated for that language, plus a small hand-written runtime and API. The C and C++ libraries are generated the same way as the others. The only shared data is the embedded locale tables.

What about locales and Unicode?

Patterns and subjects are UTF-8. Every library embeds the same generated tables, built from CLDR 48.2 and Unicode 17.0.0, for character classes, case mappings and collating data in 1,122 CLDR locales. The conformance suite checks that locale-aware behavior across every backend. The default locale is POSIX, and the generator that reproduces the tables lives in the repository.

What is Vego?

A strict subset of Go built for mechanical translation: no imports, no methods, no interfaces, no function values, no generics. The engine is written in it, so the Go library runs the source directly while the compiler exports the same code as an intermediate representation for the other printers and for Lean. The checker rejects anything outside the subset and points at the line.

Is it vibe-coded AI slop?

Revera is heavily AI-assisted. Changes are reviewed against the written specification, the POSIX standard text, differential tests, the shared conformance corpus, generated-file freshness checks, and Lean proofs with stated boundaries. These checks provide concrete evidence for a change instead of treating its origin as evidence.

Give every language the same regex.

One behavior in every language: interoperable, resource-aware POSIX regular expressions generated from one shared source.