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 Field Type Description .flagsstring The flags, such as i. .patternstring The 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.
Parameter Takes text required string
Example
.kscript XML Copy
<echo>{ /(\d{4})-(\d\d)/->match('Due 2026-11').groups }</echo>.kscript XML Copy
echo /(\d{4})-(\d\d)/->match('Due 2026-11').groups# regex ->match_all (text: string ) → list Every match, as { text, index, groups, captures } maps.
Parameter Takes text required string
Example
.kscript XML Copy
<echo>{ /\d+/->match_all('3 cats, 12 dogs')->map(fn(m) => $m.text) }</echo>.kscript XML Copy
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 ${name} are groups, or fn(match) returning text.
Parameter Takes text required string with required any value
Arguments can be named: ->replace(…, with: …).
Example
.kscript XML Copy
<echo>{ /(\d{4})-(\d\d)/->replace('2026-11', '$2/$1') }</echo>.kscript XML Copy
echo /(\d{4})-(\d\d)/->replace('2026-11', '$2/$1')# regex ->split (text: string ) → list The text split at every match.
Parameter Takes text required string
Example
.kscript XML Copy
<echo>{ /\s*[,;]\s*/->split('tea, coffee;milk') }</echo>.kscript XML Copy
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).
Parameter Takes text required string
Example
.kscript XML Copy
<echo>{ /^[a-z]+$/i->test('Hello') }</echo>.kscript XML Copy
echo /^[a-z]+$/i->test('Hello')Methods from any Methods from string