Light Dark

Functions

capture

fn (value: Str, pattern: Str): Str

Return first captured group for regex pattern in value.

Example

::hot::regex/capture("user@domain", "(\\w+)@(\\w+)")
// {"match": "user@domain", "groups": ["user", "domain"]}

capture-all

fn (value: Str, pattern: Str): Vec

Return all captured groups for regex pattern in value.

Example

::hot::regex/capture-all("a=1 b=2", "(\\w+)=(\\d+)")
// [{"match": "a=1", "groups": ["a", "1"]},
//  {"match": "b=2", "groups": ["b", "2"]}]

escape

fn (value: Str): Str

Escape special regex characters in value.

Example

::hot::regex/escape("hello.world?")  // "hello\\.world\\?"
::hot::regex/escape("[test]")        // "\\[test\\]"

find

fn (value: Str, pattern: Str): Str

Return first match of regex pattern in value with position info.

Example

::hot::regex/find("abc123def", "\\d+")
// {"match": "123", "start": 3, "end": 6}

find-all

fn (value: Str, pattern: Str): Vec

Return all matches of regex pattern in value with position info.

Example

::hot::regex/find-all("a1b22c333", "\\d+")
// [{"match": "1", "start": 1, "end": 2},
//  {"match": "22", "start": 3, "end": 5},
//  {"match": "333", "start": 6, "end": 9}]

first-match

fn (value: Str, pattern: Str): Vec

Return first match of regex pattern in value, or null if no match.

Example

::hot::regex/first-match("abc123def", "\\d+")  // "123"
::hot::regex/first-match("no digits", "\\d+")  // null

is-match

fn (value: Str, pattern: Str): Bool

Return true if regex pattern matches value.

Example

::hot::regex/is-match("abc123", "\\d+")   // true
::hot::regex/is-match("no nums", "\\d+")  // false

replace

fn (value: Str, pattern: Str, replacement: Str): Str

Replace first match of regex pattern in value with replacement.

Example

::hot::regex/replace("abc123def", "\\d+", "NUM")
// "abcNUMdef"

See also: ::hot::str/replace for simple string replacement.

replace-all

fn (value: Str, pattern: Str, replacement: Str): Str

Replace all matches of regex pattern in value with replacement.

Example

::hot::regex/replace-all("a1b2c3", "\\d+", "X")
// "aXbXcX"

split

fn (value: Str, pattern: Str): Vec

Split value by regex pattern.

Example

::hot::regex/split("apple,banana;cherry", "[,;]")
// ["apple", "banana", "cherry"]

::hot::regex/split("one   two\tthree", "\\s+")
// ["one", "two", "three"]

See also: ::hot::str/split for simple string splitting.