Manuscript Documentation
v2026.12.0

@std/regex.ms#

Import each required symbol with import Name from "@std/regex.ms".

Regex Native type#

A compiled regular expression that can be reused across input strings.

Manuscript
type Regex {
}

fn Regex.matches(text String) Bool { ... }
fn Regex.find_all(text String, max_matches Int? = null) Result[List[String], Error] { ... }
fn Regex.replace_all(text String, replacement String, max_bytes Int? = null) Result[String, Error] { ... }
fn Regex.split(text String, max_pieces Int? = null) Result[List[String], Error] { ... }
fn Regex.replace_template(text String, template String, max_bytes Int? = null) Result[String, Error] { ... }

Regex.capture#

Returns the first match as [whole, group1, …]; groups that did not participate are “”. Empty list when nothing matches.

Manuscript
fn capture(text String) List[String]

Regex.capture_all#

Like capture for every nonoverlapping match, under find_all’s match-count budget.

Manuscript
fn capture_all(text String, max_matches Int? = null) Result[List[List[String]], Error]

Regex.capture_all_spans#

Like capture_spans, for every match in capture_all order; no match gives an empty list. max_matches bounds the rows; max_captures bounds the total slots across rows, counting whole matches and unmatched groups. A negative budget returns EINVAL and exceeding one returns EOVERFLOW. These bound the output, not the search.

Manuscript
fn capture_all_spans(text String, max_matches Int? = null, max_captures Int? = null) Result[List[List[RegexSpan?]], Error]

Regex.capture_named#

Returns the first match’s named groups that participated; empty map when nothing matches.

Manuscript
fn capture_named(text String) Map[String, String]

Regex.capture_spans#

Returns the byte ranges of the first match as [whole, group1, …], or an outer null when nothing matches. A group that did not participate is an inner null; a participating empty group has start == end. max_captures bounds the slots, counting the whole match and unmatched groups. A negative budget returns EINVAL and exceeding it returns EOVERFLOW. The budget bounds the output, not input scanning or engine scratch space.

Manuscript
fn capture_spans(text String, max_captures Int? = null) Result[List[RegexSpan?]?, Error]

Regex.find_all#

Returns the text of each nonoverlapping match in order, without capture groups. A supplied max_matches is a strict budget: more matches return an error rather than a truncated list. Zero-width matches follow the engine’s rules.

Manuscript
fn find_all(text String, max_matches Int? = null) Result[List[String], Error] { ... }

Regex.find_all_spans#

Returns the byte range of each match in find_all order, without copying the matched text. max_matches is a strict output budget: a negative value returns EINVAL and more matches return EOVERFLOW.

Manuscript
fn find_all_spans(text String, max_matches Int? = null) Result[List[RegexSpan], Error]

Regex.find_span#

Returns the UTF-8 byte range of the first match, or null when nothing matches.

Manuscript
fn find_span(text String) RegexSpan?

Regex.matches#

Tests whether any match occurs; anchor the pattern explicitly to require a whole-string match.

Manuscript
fn matches(text String) Bool { ... }

Regex.replace_all#

Replaces every nonoverlapping match with replacement, used literally: $ and capture names are not expanded. max_bytes optionally bounds the UTF-8 output; a negative bound returns EINVAL and exceeding it returns EOVERFLOW.

Manuscript
fn replace_all(text String, replacement String, max_bytes Int? = null) Result[String, Error] { ... }

Regex.replace_template#

Like replace_all, but expands $1, ${name} and $$ in template from each match. The syntax is Rust’s: write ${1}x, not $1x.

Manuscript
fn replace_template(text String, template String, max_bytes Int? = null) Result[String, Error] { ... }

Regex.split#

Splits text around every match, always returning at least one piece. max_pieces is a strict budget like find_all’s.

Manuscript
fn split(text String, max_pieces Int? = null) Result[List[String], Error] { ... }

RegexSpan Type#

A match or capture range in UTF-8 bytes, with an exclusive end; no normalization is applied. Example: a match of é in aé spans bytes 1 through 3, not scalar positions 1 through 2. Extract text with data.decode_utf8_range(span.start, span.end) on its original Bytes.

Manuscript
type RegexSpan {
    start Int
    end Int
}

RegexSpan.end#

Exclusive UTF-8 byte offset; equal to start for a participating empty match.

Manuscript
end Int

RegexSpan.start#

Zero-based inclusive UTF-8 byte offset in the input string.

Manuscript
start Int

compile Function#

Compiles a regular expression. Invalid pattern syntax is returned as an error.

Manuscript
fn compile(pattern String) Result[Regex, Error] { ... }