Skip to content

Regex

1 min read

Import: import system.text;

Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.

Regex

A compiled regular expression. Use Regex.compile to report invalid patterns.

public class Regex

compile

Compiles a pattern with optional flags, returning an error for invalid patterns.

public static fun compile(
    pattern: string,
    flags: RegexFlags = RegexFlags.None
): Result<Regex, RegexError>

test

Returns whether the regular expression matches anywhere in input.

public fun test(borrow input: string): bool

replace

Replaces matching text. Replaces every match with Global; otherwise replaces only the first.

public fun replace(input: string, replacement: string): string

match

Returns complete matches with Global, or the first match followed by its capture groups otherwise. Returns an empty array when unmatched.

public fun match(input: string): string[]

match_info

Returns the first match and its named and numbered capture groups, or None when unmatched.

public fun match_info(input: string): Option<RegexMatchInfo>