@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.
type Regex:
fn matches(text: String) -> Bool:
fn find_all(text: String, max_matches: Optional[Int] = none) -> Result[List[String], RegexError]:
fn replace_all(text: String, replacement: String, max_bytes: Optional[Int] = none) -> Result[String, RegexError]:Regex.find_all#
Returns nonoverlapping full-match text in occurrence order, excluding capture groups. A supplied cap is a strict budget, not truncation; zero-width matches follow native regexp rules.
fn find_all(text: String, max_matches: Optional[Int] = none) -> Result[List[String], RegexError]:Regex.matches#
Tests whether any match occurs; anchor the pattern explicitly to require a whole-string match.
fn matches(text: String) -> Bool:Regex.replace_all#
Replaces every nonoverlapping match with literal replacement text; $ and capture names are not expanded. max_bytes optionally bounds UTF-8 output; negatives return InvalidInput, exhaustion LimitExceeded.
fn replace_all(text: String, replacement: String, max_bytes: Optional[Int] = none) -> Result[String, RegexError]:RegexError Alternative#
Errors returned for invalid patterns or configured result limits.
type RegexError:
case InvalidInput
case InvalidData
case LimitExceededimpl Error for RegexError:
fn message() -> String:RegexError.InvalidData#
Pattern syntax is invalid for the native RE2-compatible regular-expression engine.
case InvalidDataRegexError.InvalidInput#
A supplied match-count or output-byte budget is negative.
case InvalidInputRegexError.LimitExceeded#
More matches exist than permitted, or replacement output exceeds its byte budget.
case LimitExceededRegexError.Error.message#
Returns a regular-expression-prefixed diagnostic without echoing pattern or input text.
fn message() -> String:compile Function#
Compiles a regular expression. Invalid pattern syntax is returned as an error.
fn compile(pattern: String) -> Result[Regex, RegexError]: