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 as Option<string>. A missing match is None; an empty match stays Some("").
replaceReplaces all regular-expression matches in a string.
splitSplits a string on regular-expression matches.
capturesReturns the capture groups of the first match. Group 0 and every participating group are Some; an unmatched optional group is None, and a missing match is an empty array.

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) -> Option<string>

Returns the first substring matched by a regular expression as Option<string>. A missing match is None; an empty match stays Some("").

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) -> [string]

Splits a string on regular-expression matches.

captures

fn captures(pattern: string, text: string) -> [Option<string>]

Returns the capture groups of the first match. Group 0 and every participating group are Some; an unmatched optional group is None, and a missing match is an empty array.