re

re

Regex builtin namespace.

Runtime support: native and WebAssembly.

Import

use re;

Functions

FunctionDescription
matchReturns whether a regular expression matches the input text.
findReturns the first substring matched by a regular expression.
replaceReplaces all regular-expression matches in a string.
splitSplits a string on regular-expression matches.
capturesReturns the capture groups produced by the first regular-expression match.

Function details

match

fn match(pattern: string, text: string) -> bool

Returns whether a regular expression matches the input text.

find

fn find(pattern: string, text: string) -> string
null

Returns the first substring matched by a regular expression.

replace

fn replace(pattern: string, text: string, replacement: string) -> string

Replaces all regular-expression matches in a string.

split

fn split(pattern: string, text: string) -> array

Splits a string on regular-expression matches.

captures

fn captures(pattern: string, text: string) -> array

Returns the capture groups produced by the first regular-expression match.