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.regexpWhat it does
Section titled “What it does”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.
Quickstart
Section titled “Quickstart”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}"),}Method syntax
Section titled “Method syntax”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)}Regexp constructor
Section titled “Regexp constructor”| Function | Signature | Description |
|---|---|---|
Regexp.new |
Regexp.new(pat: str) -> Result<regexp, str> |
Constructor namespace spelling |
API reference
Section titled “API reference”7 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.
See also
Section titled “See also”std.str— Strings: search, slicing, casing, padding, splitting and zero-allocation builders.
Full index: API reference · Standard library