Skip to content

std.regexp - ZZ

Compiled patterns are opaque "regexp" handles, so method syntax works. Backed by the same engine on VM and AOT. compile is fallible (bad patterns yield .err, never panic).

import std.regexp

std.regexp compiles regex patterns into reusable handles, then matches, finds, replaces, and captures. Compile once, reuse many times — handles are cheap to query, compilation is the cost.

import std.regexp
match regexp.compile(`^[0-9a-f]{8}$`) {
.ok(re) => {
println(re.is_match("deadbeef")) // true
match re.find("xx deadbeef yy") {
.some(m) => println("found {m}"),
.none => println("no match"),
}
println(re.replace_all("a1 b2", "X")) // "aX bX"
println(re.captures("2024-02-29")) // groups, "" for unmatched, [] on no match
},
.err(e) => println("bad pattern: {e}"),
}

Regexp handles dispatch method calls:

import std.regexp
func main() -> Result<int, str> {
re := regexp.compile(`\d+`)?
re.is_match("abc123") // true
re.find("abc123") // .some("123")
re.replace_all("a1b2", "X") // "aXbX"
re.captures("2024-02-29") // ["2024-02-29", ...]
return .ok(0)
}
Function Signature Description
Regexp.new Regexp.new(pat: str) -> Result<regexp, str> Constructor namespace spelling

7 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
Regexp.new new(pat: str) -> Result<regexp, str> Constructor namespace spelling
std.regexp.captures captures(re: regexp, s: str) -> [str] Group list (“” unmatched, [] no match)
std.regexp.compile compile(pat: str) -> Result<regexp, str> Compile pattern (.err on bad pattern)
std.regexp.find find(re: regexp, s: str) -> Option<str> First match
std.regexp.is_email is_email(s: str) -> bool Email convenience predicate
std.regexp.is_match is_match(re: regexp, s: str) -> bool Full match?
std.regexp.replace_all replace_all(re: regexp, s: str, rep: str) -> str Replace all matches
  • std.str — Strings: search, slicing, casing, padding, splitting and zero-allocation builders.

Full index: API reference · Standard library