KScript docs
EN

regex fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.flagsstringThe flags, such as i.
.patternstringThe pattern, without slashes or flags.

From KScript.Core

#regex->match(text: string) → map

The first match: { text, index, groups, captures }, where groups holds named groups (?<name>...) and captures numbered ones. null if none.
ParameterTakes
text requiredstring
Example
<echo>{ /(\d{4})-(\d\d)/->match('Due 2026-11').groups }</echo>
echo /(\d{4})-(\d\d)/->match('Due 2026-11').groups

#regex->match_all(text: string) → list

Every match, as { text, index, groups, captures } maps.
ParameterTakes
text requiredstring
Example
<echo>{ /\d+/->match_all('3 cats, 12 dogs')->map(fn(m) => $m.text) }</echo>
echo /\d+/->match_all('3 cats, 12 dogs')->map(fn(m) => $m.text)

#regex->replace(text: string, with) → string

The text with every match replaced. with is text, where $1 and $ are groups, or fn(match) returning text.

ParameterTakes
text requiredstring
with requiredany value

Arguments can be named: ->replace(…, with: …).

Example
<echo>{ /(\d{4})-(\d\d)/->replace('2026-11', '$2/$1') }</echo>
echo /(\d{4})-(\d\d)/->replace('2026-11', '$2/$1')

#regex->split(text: string) → list

The text split at every match.
ParameterTakes
text requiredstring
Example
<echo>{ /\s*[,;]\s*/->split('tea, coffee;milk') }</echo>
echo /\s*[,;]\s*/->split('tea, coffee;milk')

#regex->test(text: string) → bool

True when the text matches somewhere (use ^ and $ to match all of it).
ParameterTakes
text requiredstring
Example
<echo>{ /^[a-z]+$/i->test('Hello') }</echo>
echo /^[a-z]+$/i->test('Hello')

Methods from any

Methods from string