tur/re
pure-Turmeric regular expressions (POSIX ERE subset).
Since: Phase B1 (libc); pure-Turmeric rewrite 2026-07
RxCls
(defdata RxCls :copy (RxClsNil) (RxClsRange))
Regex
(defdata Regex :copy (RChar) (RAny) (RClass) (RStar) (RPlus) (ROpt) (RConcat) (RAlt) (RGroup) (REmpty) (RNever) (RBegin) (REnd))
RxPos
(defdata RxPos :copy (RxNil) (RxCons))
RxPair
(defdata RxPair (RxIP))
RxParse
(defdata RxParse (RxPR))
RxStrs
(defdata RxStrs (RxStrsNil) (RxStrsCons))
re-pos-append
(re-pos-append [a : RxPos b : RxPos] :)
re-pos-contains?
(re-pos-contains? [a : RxPos v : int] :)
re-pos-empty?
(re-pos-empty? [a : RxPos] :)
re-pos-len
(re-pos-len [a : RxPos] :)
re-pos-max
(re-pos-max [a : RxPos acc : int] :)
re-pos-dedup-go
(re-pos-dedup-go [a : RxPos seen : RxPos] :)
re-pos-dedup
(re-pos-dedup [a : RxPos] :)
re-range-list
(re-range-list [lo : int hi : int] :)
re-cstr-eq-loop
(re-cstr-eq-loop [a : cstr b : cstr i : int n : int] :)
re-cstr-eq?
(re-cstr-eq? [a : cstr b : cstr] :)
re-class-match?
(re-class-match? [items : RxCls b : int] :)
re-step-char
(re-step-char [starts : RxPos input : cstr len : int c : int] :)
re-step-any
(re-step-any [starts : RxPos input : cstr len : int] :)
re-step-class
(re-step-class [starts : RxPos input : cstr len : int neg : bool items : RxCls] :)
re-step-begin
(re-step-begin [starts : RxPos] :)
re-step-end
(re-step-end [starts : RxPos len : int] :)
re-run-k
(re-run-k [re : Regex starts : RxPos input : cstr len : int] :)
re-digit?
(re-digit? [c : int] :)
re-read-int
(re-read-int [input : cstr len : int pos : int acc : int] :)
re-repeat-n
(re-repeat-n [atom : Regex n : int] :)
re-repeat-opt
(re-repeat-opt [atom : Regex n : int] :)
re-parse-brace
(re-parse-brace [input : cstr len : int atom : Regex pos : int] :)
re-apply-quant
(re-apply-quant [input : cstr len : int ra : Regex pos : int] :)
re-parse-escape
(re-parse-escape [input : cstr len : int pos : int] :)
re-scan-name-end
(re-scan-name-end [input : cstr len : int pos : int] :)
re-posix-ranges
(re-posix-ranges [name : cstr acc : RxCls] :)
re-posix-open?
(re-posix-open? [input : cstr len : int pos : int] :)
re-range-here?
(re-range-here? [input : cstr len : int pos : int] :)
re-re-parse-class-items
(re-re-parse-class-items [input : cstr len : int pos : int neg : bool acc : RxCls] :)
re-parse-class
(re-parse-class [input : cstr len : int pos : int] :)
re-concat-end?
(re-concat-end? [input : cstr len : int pos : int] :)
re-parse-go
(re-parse-go [input : cstr len : int pos : int mode : int acc : Regex] :)
re-find-from
(re-find-from [re : Regex input : cstr len : int from : int] :)
re-find-all-go
(re-find-all-go [re : Regex input : cstr len : int from : int] :)
re-replace-go
(re-replace-go [re : Regex input : cstr len : int from : int replacement : cstr acc : cstr] :)
re/compile
(re/compile [pattern : cstr] :)
compile a regular expression pattern into a Regex.
| pattern | NUL-terminated regex pattern cstr (POSIX ERE subset) |
A Regex value (the parsed AST). Parsing is total: a malformed pattern is parsed best-effort rather than rejected, so there is no error return.
(re/compile "([0-9]+)") ; => <Regex>
Since: Phase B2
re/match?
(re/match? [re : Regex input : cstr] :)
test whether a pattern matches anywhere in input.
| re | compiled Regex from re/compile | |
| input | input string cstr |
true if the pattern matches at some position, false otherwise.
(re/match? (re/compile "[0-9]+") "abc123") ; => true
Since: Phase B2
re/match
(re/match [re : Regex input : cstr] :)
return the leftmost-longest whole match as an Option.
| re | compiled Regex from re/compile | |
| input | input string cstr |
(some matched-substring) on a match, or (none) if there is no match.
(re/match (re/compile "[0-9]+") "a12b") ; => (some "12")
Since: Phase B2 (pure-Turmeric rewrite)
re/find-all
(re/find-all [re : Regex input : cstr] :)
all non-overlapping matches, left to right.
| re | compiled Regex from re/compile | |
| input | input string cstr |
An RxStrs cons list of matched substrings (empty list if none).
(re/find-all (re/compile "[0-9]+") "a1b22c") ; => ("1" "22")
Since: Phase B2 (pure-Turmeric rewrite)
re/replace
(re/replace [re : Regex input : cstr replacement : cstr] :)
replace the first match with a literal replacement.
| re | compiled Regex from re/compile | |
| input | input string cstr | |
| replacement | literal replacement cstr (no backreferences) |
A fresh cstr with the first match replaced, or a copy of input if there is no match.
(re/replace (re/compile "world") "hello world" "WORLD") ; => "hello WORLD"
Since: Phase B2
re/replace-all
(re/replace-all [re : Regex input : cstr replacement : cstr] :)
replace all non-overlapping matches with a literal.
| re | compiled Regex from re/compile | |
| input | input string cstr | |
| replacement | literal replacement cstr (no backreferences) |
A fresh cstr with every match replaced.
(re/replace-all (re/compile "[0-9]") "a1b2c3" "X") ; => "aXbXcX"
Since: Phase B2
re/free
(re/free [re : Regex] :)
no-op shim (a Regex is a GC/heap value, not a malloc'd handle).
| re | a Regex (ignored) |
Since: Phase B2 (no-op since the pure-Turmeric rewrite)
re/match-free
(re/match-free [m : (Option cstr)] :)
no-op shim; the Option result needs no manual free.
re/find-all-free
(re/find-all-free [lst : RxStrs] :)
no-op shim; the RxStrs result needs no manual free.
re/wrap-paren
(re/wrap-paren [p : cstr] :)
internal: wrap one pattern as "(p)" (heap; caller frees).
re/union-acc
(re/union-acc [acc : cstr patterns : int] :)
internal: right-fold the rest onto acc, joining with "|".
re/union-patterns
(re/union-patterns [patterns : int] :)
build an alternation regex string from a cons list of
| patterns | :int cons list of cstr patterns (head = cstr pointer) |
A heap cstr containing the unioned pattern, or 0.
(re/union-patterns (cons "[A-Za-z]+" (cons "[0-9]+" 0)))
; => "([A-Za-z]+)|([0-9]+)"
Since: Phase RU1
re/compile-union
(re/compile-union [patterns : int] :)
compile an alternation of multiple patterns into a Regex.
| patterns | :int cons list of cstr patterns (head = cstr pointer) |
A compiled Regex on success, or (RNever) -- a regex that matches nothing -- if the input list is empty or contains a null element.
(re/compile-union (cons "[A-Za-z]+" (cons "[0-9]+" 0))) ; => <Regex>
Since: Phase RU2