Skip to content
Systems programming for what’s next.
— Vex

regex — Overview ​

std/regex is a pure-Vex, byte-oriented regular-expression engine with deterministic resource limits and no catastrophic backtracking.

vex
import { Match, Regex } from "regex";

fn main(): i32 {
    let regex = Regex.new("(\\w+)@(\\w+\\.\\w+)");
    let! result = Match.new();
    if regex.exec("mail: user@example.com", &result!) {
        match result.group(1) {
            Some(value) => { $println(value); },
            None => { $println("No capture"); },
        }
    }
    return 0;
}

With the regex module available, this example prints user. Check the compiler and standard-library versions for your release.

The public operations have distinct semantics:

  • test searches anywhere;
  • isMatch requires the entire input;
  • exec returns the leftmost match and capture groups.

Internally, pure literals and SIMD-backed prefix searches feed a one-pass DFA or a parallel Thompson NFA. Capture extraction uses a prioritized Pike VM with workspace reused through Match. Pattern-specific email/router shortcuts are not part of the engine.

Validation and performance ​

The source tree contains O0/O3 tests and a benchmark harness that makes inputs opaque and consumes results through a compiler barrier. Historical Apple arm64 O3 figures reported 7.58 ns for literal search, 21.07 ns for group-free literal exec, 565.57 ns for capture extraction, and 24.0 GB/s for a 9 KiB prefix miss, with a 1-second measurement cap. These numbers have not been revalidated against this documentation build and are not a current performance guarantee.

Source layout ​

FileResponsibility
parser.vxBounded syntax parser and validation
ast.vxPattern, sequence, class and capture types
prog.vxThompson bytecode and semantic metadata
thompson.vxAST-to-bytecode compiler
class_match.vxCanonical byte-class semantics
onepass.vxDeterministic transition-table engine
thompson_exec.vxLinear boolean search/full-match engine
pike_vm.vxPrioritized capture engine
regex.vxPublic Regex, Matcher and Match API

Released under the MIT License.