← Standard library

Regex

sealed class Regex
import Regex from Wax;

A compiled regular expression created with Wax regex(...) syntax. Literal patterns are checked at compile time; dynamic patterns can report RegexError. Matching works in Unicode code points, while public indices, lengths, and starting positions are UTF-8 byte offsets. Searches find matches at or after the start rather than implicitly anchoring the entire input. Non-overlapping iteration advances after empty matches to ensure progress.

import Regex from Wax;
api fn Main() : int32 {
    Regex digits = regex(/[0-9]+/);
    var match = digits.Match("item 42");
    return match != null ? match!.length : 0;
}

Regex.wax:77

Inherits from object. Follow these links for inherited members.

Members

optionsfield

public readonly RegexOptions options

The flags used to compile this expression.

Regex.wax:82

patternfield

public readonly string pattern

The original expression text.

Regex.wax:86

IsMatchmethod

public fn IsMatch(string text) : bool

Returns whether the expression finds a match anywhere in the input.

Regex.wax:251

IsMatchAtmethod

public fn IsMatchAt(string text, int32 startAt) : bool

Searches at or after byte offset startAt. Negative offsets start at zero; offsets inside a code point advance to the next boundary, and offsets past the input clamp to the end.

Regex.wax:265

Matchmethod

public fn Match(string text) : Match?

Returns the first match, or null if no match exists.

Regex.wax:279

MatchAtmethod

public fn MatchAt(string text, int32 startAt) : Match?

Returns the first match at or after the starting byte offset, or null. The offset follows the clamping and boundary rules of IsMatchAt.

Regex.wax:296

Countmethod

public fn Count(string text) : int32

Counts non-overlapping matches, including empty matches. An empty match advances by one code point before searching again.

Regex.wax:314

Matchesmethod

public fn Matches(string text) : MatchIterator

Returns an iterator over non-overlapping matches from the start of the input.

Regex.wax:343

MatchesAtmethod

public fn MatchesAt(string text, int32 startAt) : MatchIterator

Returns a non-overlapping match iterator starting at the supplied byte offset, using the same starting-position rules as IsMatchAt.

Regex.wax:351

Escapemethod

public static fn Escape(string text) : string

Prefixes regex metacharacters with a backslash for literal matching. Does not additionally escape whitespace or #-comments for FreeSpacing mode.

Regex.wax:359

Replacemethod

public fn Replace(string text, string replacement) : string

Replaces non-overlapping matches. Replacement syntax supports $$ for a dollar sign, $& for the full match, $1$99 for captures, and $<name> for named captures. Unmatched captures contribute empty text.

Regex.wax:399

ReplaceCountmethod

public fn ReplaceCount(string text, string replacement, int32 count) : string

Uses the same substitutions as Replace, stopping after at most a positive count matches. A nonpositive count means no limit.

Regex.wax:407

ReplaceWithmethod

public fn ReplaceWith(string text, fn<(Match) : string> evaluator) : string

Replaces each non-overlapping match with the string returned by the evaluator. Evaluator output is literal text, without replacement-template expansion.

Regex.wax:561

Splitmethod

public fn Split(string text) : string[]

Splits around non-overlapping matches, preserving empty segments. Capture groups are not inserted into the result.

Regex.wax:581

SplitCountmethod

public fn SplitCount(string text, int32 count) : string[]

Splits into at most a positive count segments, retaining the remainder as the last segment. A nonpositive count means no limit.

Regex.wax:589