Tanguv0.35.0
Text & i18n9 exports
Raw Markdown

/regex

Compiled regular expressions (Regex) with matching, capture extraction, replacement, and splitting.

(use /regex)

Functions & symbols#

Regex#

constructor
(Regex pattern) -> Regex

Compiles a regular expression `pattern` into a reusable `Regex` value.

ParameterTypeOptionalDescription
patternStringrequiredRegular expression pattern string
Returns:Any
(let re (regex/Regex "^v(\\d+)\\.(\\d+)"))

capture#

function
(capture re text) -> (Or String None)

Returns the first full match substring in `text`, or `()` if none.

ParameterTypeOptionalDescription
reRegex | StringrequiredCompiled Regex or pattern
textStringrequiredInput text
Returns:Any
(regex/capture "[0-9]+" "port=8080") ; -> "8080"

captures#

function
(captures re text) -> (Or Map Array None)

Extracts positional and/or named capture groups from the first match of `re` in `text`.

ParameterTypeOptionalDescription
reRegex | StringrequiredCompiled Regex or pattern
textStringrequiredInput text
Returns:Any
(regex/captures "(?<k>\\w+)=(?<v>\\d+)" "port=8080")

captures-all#

function
(captures-all re text) -> Array

Returns all successive non-overlapping capture matches in `text` as an Array.

ParameterTypeOptionalDescription
reRegex | StringrequiredCompiled Regex or pattern
textStringrequiredInput text
Returns:Any
(regex/captures-all "\\w+" "a b c")

is-matching?#

function
(is-matching? re text) -> Bool

Returns `true` if `re` matches anywhere inside `text`.

ParameterTypeOptionalDescription
reRegex | StringrequiredCompiled Regex or pattern string
textStringrequiredInput text to test
Returns:Any
(regex/is-matching? "\\d+" "id-42") ; -> true

matching?#

function
(matching? re text) -> Bool

Alias of `is-matching?`.

ParameterTypeOptionalDescription
reRegex | StringrequiredCompiled Regex or pattern
textStringrequiredInput text
Returns:Any
(regex/matching? "^[a-z]+$" "tangu")

replace#

function
(replace text re replacement) -> String

Replaces all matches of `re` in `text` with `replacement`.

ParameterTypeOptionalDescription
textStringrequiredInput text
reRegex | StringrequiredRegex or pattern to replace
replacementStringrequiredReplacement string (supports $1, $name backreferences)
Returns:Any
(regex/replace "2026-05-01" "-" "/") ; -> "2026/05/01"

split#

function
(split sep-re text) -> (Array String)

Splits `text` around occurrences matching `sep-re`.

ParameterTypeOptionalDescription
sep_reRegex | StringrequiredSeparator Regex or pattern
textStringrequiredInput text to split
Returns:Any
(regex/split "[,\\s]+" "a, b  c")

split-matches#

function
(split-matches match-re text) -> (Array String)

Splits `text` while alternating matched substrings and unmatched slices.

ParameterTypeOptionalDescription
match_reRegex | StringrequiredRegex matching tokens to preserve alongside delimiters
textStringrequiredInput text
Returns:Any
(regex/split-matches "\\d+" "a1b2c")