text/re
lib/text/re.vklib/text/re.vk
Pure-Veko linear-time Thompson NFA regular expression engine (O(n * m) worst-case, zero backtracking).
Supports . wildcard, ^ / $ anchors, *, +, ? quantifiers, | alternation, (...) grouping,
character classes [a-z0-9_] / [^...], and \d, \D, \w, \W, \s, \S escapes.
Zero capabilities required; works identically on VM, Wasm 3.0, and Native.
NfaInst = struct { op i64, ch i64 = ..., out i64 = ..., out1 i64 = ..., cset bytes = ..., neg bool = ... }
Single compiled Thompson NFA instruction.
Regex = struct { pattern str, insts block[NfaInst], start_pc i64 }
Compiled regular expression automaton.
Match = struct { start i64, end i64, text str }
Byte-span match result (start..end slice of the input string).
compile = fn [pattern str] Regex
Compiles pattern into a linear-time Regex NFA (returns err on invalid syntax; combine with /or).
use [re = text/re]
rx = re/compile 'v[0-9]+\\.[0-9]+'
ms = re/find-all rx 'release v1.0 and v2.14 ready'
if (len ms) != 2 or ms[0].text != 'v1.0' or ms[1].text != 'v2.14' [ err 're find-all' ] else [ .ok ]
match? = fn [pattern str, text str] bool
Convenience one-shot match test compiling pattern and testing text.
find = fn [rx Regex, text str] Match
Finds the leftmost match of rx in text, or returns err if not found (combine with /or).
find-all = fn [rx Regex, text str] block[Match]
Finds all non-overlapping matches of rx in text.
replace-all = fn [rx Regex, text str, replacement str] str
Replaces all non-overlapping matches of rx in text with replacement.
split = fn [rx Regex, text str] block[str]
Splits text around non-overlapping non-empty matches of rx.