Skip to content

regex — Overview

A complete, SIMD-accelerated regex engine written in pure Vex. The engine compiles patterns into Thompson NFA bytecode and employs multiple execution strategies for optimal performance.

Execution Strategy Pipeline

When you call regex.test(text), the engine routes through the fastest available path:

Pattern Compile → Thompson NFA → Bytecode Program

                  ┌────────────────────┼────────────────────┐
                  ↓                    ↓                    ↓
            One-Pass DFA         SIMD Prefix        Lazy DFA
           (small patterns)    (multi-byte lit)   (complex patterns)
                  ↓                    ↓                    ↓
              Direct match      Fast candidate       On-demand
              (no backtrack)     pre-filter          state cache

Quick Start

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

let re = Regex.new("\\d{3}-\\d{4}");

// Simple test
if re.test("Call 555-1234 now") {
    println("Found phone number!");
}

// Extract match
let! m = Match.new();
if re.exec("Call 555-1234 now", &m) {
    println("Match: {m.value()}");       // "555-1234"
    println("Start: {m.start()}");       // position
}

Module Architecture

FileLinesPurpose
parser.vx18,837Regex syntax parser → AST
ast.vx6,472Pattern/Sequence/Span types
thompson.vx14,511NFA compiler (AST → bytecode)
prog.vx4,296Bytecode program + metadata
onepass.vx14,227One-pass DFA builder & executor
lazy_dfa.vx15,444Lazy DFA with on-demand states
thompson_fast.vx22,240SIMD-accelerated NFA execution
thompson_exec.vx7,729Basic Thompson NFA executor
matcher.vx17,197High-level search + capture groups
regex.vx6,179Public API (Regex, Match)

Released under the MIT License.