regex — Overview
std/regex is a pure-Vex, byte-oriented regular-expression engine with deterministic resource limits and no catastrophic backtracking.
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:
testsearches anywhere;isMatchrequires the entire input;execreturns 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
| File | Responsibility |
|---|---|
parser.vx | Bounded syntax parser and validation |
ast.vx | Pattern, sequence, class and capture types |
prog.vx | Thompson bytecode and semantic metadata |
thompson.vx | AST-to-bytecode compiler |
class_match.vx | Canonical byte-class semantics |
onepass.vx | Deterministic transition-table engine |
thompson_exec.vx | Linear boolean search/full-match engine |
pike_vm.vx | Prioritized capture engine |
regex.vx | Public Regex, Matcher and Match API |