v2026.11.3
All Bundles
Bundle

Regular expression matching and replacement. RegEx compiles a pattern once and supports full match, substring search, numbered capture groups, and global replacement. Link with -lib regex.

Result

RegEx result: the matched text, its position, and the text of each numbered capture group

Operations

GetGroup #

Gets the text captured by a group. Groups are numbered from 1 by their opening '(' left to right; '(?:...)' does not capture. Group 0 is the whole match. In a repeated group the last iteration wins.

method : public : GetGroup(index:Int) ~ String

Parameters

NameTypeDescription
indexIntgroup number

Return

TypeDescription
Stringcaptured text, or Nil if the group did not take part in the match or does not exist

Example

re := RegEx->New("(\\d+)-(\\d+)");
r := re->FindFirst("call 555-1234 now");
if(r <> Nil) {
  r->GetGroup(1)->PrintLine();
  r->GetGroup(2)->PrintLine();
};

GetGroupStart #

Gets the starting index of the text captured by a group

method : public : GetGroupStart(index:Int) ~ Int

Parameters

NameTypeDescription
indexIntgroup number, 0 is the whole match

Return

TypeDescription
Intstarting index, or -1 if the group did not take part in the match or does not exist

GetLength #

Gets the string length of the match

method : public : GetLength() ~ Int

Return

TypeDescription
Intstring length of the match

Example

re := RegEx->New("\\w+");
r := re->FindFirst("hello world");
if(r <> Nil) {
  Console->PrintLine(r->GetLength());
};

GetStart #

Gets the starting index of match

method : public : GetStart() ~ Int

Return

TypeDescription
Intstarting index of match

Example

re := RegEx->New("\\d+");
r := re->FindFirst("price: 99 dollars");
if(r <> Nil) {
  Console->PrintLine(r->GetStart());
};

GetValue #

Gets the string value

method : public : GetValue() ~ String

Return

TypeDescription
Stringstring value

Example

re := RegEx->New("[A-Z][a-z]+");
r := re->FindFirst("The Quick Brown Fox");
if(r <> Nil) {
  r->GetValue()->PrintLine();
};

GroupCount #

Gets the number of capture groups in the pattern, not counting group 0 (the whole match)

method : public : GroupCount() ~ Int

Return

TypeDescription
Intnumber of capture groups

New # constructor

Creates a result without capture groups

New(start:Int, length:Int, value:String)

Parameters

NameTypeDescription
startIntstarting index of the match
lengthIntlength of the match
valueStringmatched string

New # constructor

Creates a result with capture groups

New(start:Int, length:Int, value:String, group_starts:Int[], group_values:String[])

Parameters

NameTypeDescription
startIntstarting index of the match
lengthIntlength of the match
valueStringmatched string
group_startsIntstart index of each group, index 0 is the whole match, -1 if a group did not take part
group_valuesStringtext of each group, index 0 is the whole match, Nil if a group did not take part

ToString #

Gets the string representation

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Example

re := RegEx->New("\\d+");
results := re->Find("a1 b22 c333")<Result>;
each(r := results) {
  r->ToString()->PrintLine();
};