Skip to content

std/regex

Regular expressions backed by Go’s RE2-compatible regexp engine. Use raw typed literals for readable patterns, such as Regex`\d+.

Import with import std/regex.

Types

type Regex

opaque — construction surface is private to its defining module

A compiled regular expression.

Nomi regexes use Go’s regexp package, so matching is RE2-style: predictable and non-backtracking, without lookaround or backreferences. Prefer raw typed literals for patterns so regex escapes stay readable: try Regex`\d+.

fn compile(pattern: String): Result<Regex, String>

type function on Regex

Compile a pattern into a Regex.

fn pattern(re: Regex): String

type function on Regex

Return the source pattern for a compiled regex.

fn match?(re: Regex, value: String): Bool

type function on Regex

True if the regex matches anywhere in value.

fn find(re: Regex, value: String): Maybe<String>

type function on Regex

Return the first matching substring.

fn find_all(re: Regex, value: String): List<String>

type function on Regex

Return every non-overlapping matching substring.

fn replace_all(re: Regex, value: String, replacement: String): String

type function on Regex

Replace every non-overlapping match with replacement.

Replacement text follows Go’s regexp rules, so $1, ${name}, and friends expand capture groups.

fn split(re: Regex, value: String): List<String>

type function on Regex

Split around every non-overlapping match.

fn from_fragments(fragments: List<Fragment<String>>): Result<Regex, String>

impl Literal.from_fragments

fn to_string(re: Regex): String

impl Display.to_string

The source pattern.

fn inspect(re: Regex): String

impl Debug.inspect