v2026.11.0
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.

RegEx

Regular expression engine. A match is the leftmost-longest one; when several paths give that match, capture groups take their values from the greedy (highest-priority) path.

Support for following patterns:

  • any ‐ .
  • optional ‐ ?
  • zero or more repetitions ‐ *
  • one or more repetitions ‐ +
  • repeat ‐ {least} or {least, most}; a count is at most 1000, least may not exceed most, and a pattern that expands to more than 100000 instructions (nested repeats multiply) is not accepted: IsOk() is false
  • start of input ‐ ^
  • end of input ‐ $
  • (one|two|three) ‐ numbered capture group, see Result->GetGroup
  • (?:one|two) ‐ non-capturing group
  • [abc], [a-zA-Z0-9_], [.,;] ‐ character class (several ranges and literal punctuation)
  • [^abc] ‐ negated character class
  • inside a class: \d \w \s \D \W \S, \] \\ \- and other escaped literals; a leading or trailing '-' and a ']' first are literals

Support for following special groups:

  • word ‐ \w
  • not word ‐ \W
  • digit ‐ \d
  • not digit ‐ \D
  • white space ‐ \s
  • not white space ‐ \S
  • word boundary ‐ \b
  • not a word boundary ‐ \B
  • newline, carriage return, tab ‐ \n \r \t

Example

output := HttpsClient->New()->QuickGet(Web.HTTP.Url->New(url))->ToString();
output_len := output->Size();
"URL: {$output}, read: {$output_len} character(s)"->PrintLine();

"running regex..."->PrintLine();
expr := "(href|HREF|src|SRC)=(\"|')(http://|https://|/)?((\\w|\\d|-|_)+(\\.|/)?)+(\\?(\\w|\\d|-|_)+=(\\w|\\d|-|_)+)?(&(\\w|\\d|-|_)+=(\\w|\\d|-|_)+)?(\"|')";

found := Query.RegEx.RegEx->New(expr)->Find(output)<Result>;
"---"->PrintLine();
each(i : found) {
   found->Get(i)->ToString()->PrintLine();
};

Operations

Find #

Finds all non-empty, non-overlapping occurrences

method : public : Find(stream_in:String) ~ Vector<Result>

Parameters

NameTypeDescription
stream_inStringstring to match against

Return

TypeDescription
Vector<Result>vector of string matches

Example

re := RegEx->New("\\d+");
results := re->Find("1 cat, 2 dogs, 3 birds")<Result>;
each(r := results) {
  r->GetValue()->PrintLine();
};

FindFirst #

Matches the first occurrence

method : public : FindFirst(stream_in:String) ~ Result

Parameters

NameTypeDescription
stream_inStringstring to match against

Return

TypeDescription
Resultmatched string if found, empty string otherwise

Example

re := RegEx->New("[A-Z][a-z]+");
result := re->FindFirst("Hello World");
if(result <> Nil) {
  result->GetValue()->PrintLine();
  Console->PrintLine(result->GetStart());
};

IsOk #

Check of the regex was parsed correctly

method : public : IsOk() ~ Bool

Return

TypeDescription
Booltrue if parsed, false otherwise

Example

re := RegEx->New("[a-z]+");
if(re->IsOk()) {
  "pattern compiled ok"->PrintLine();
};

Match #

Matches as much of the string as possible

method : public : Match(stream_in:String) ~ String

Parameters

NameTypeDescription
stream_inStringstring to match against

Return

TypeDescription
Stringmatched string if found, empty string otherwise

Example

re := RegEx->New("\\w+");
matched := re->Match("hello world");
matched->PrintLine();

Match #

Matches as much of the string as possible

method : public : Match(stream_in:String, offset:Int) ~ String

Parameters

NameTypeDescription
stream_inStringstring to match against
offsetIntoffset into the to match against

Return

TypeDescription
Stringmatched string if found, empty string otherwise

Example

re := RegEx->New("\\d+");
matched := re->Match("skip 42 here", 5);
matched->PrintLine();

MatchExact #

Looks for an exact regex match

method : public : MatchExact(stream_in:String) ~ Bool

Parameters

NameTypeDescription
stream_inStringstring to match against

Return

TypeDescription
Booltrue if exact, false otherwise

Example

re := RegEx->New("\\d{4}-\\d{2}-\\d{2}");
if(re->MatchExact("2025-06-15")) {
  "valid date format"->PrintLine();
};

New # constructor

Default constructor

New(stream_in:String)

Parameters

NameTypeDescription
stream_inStringregex pattern

Example

re := RegEx->New("\\d+");
if(re->IsOk()) {
  results := re->Find("order 42 ships on day 7")<Result>;
  each(r := results) {
    r->GetValue()->PrintLine();
  };
};

ReplaceAll #

Replaces all occurrences of the given string

method : public : ReplaceAll(stream_in:String, replace:String) ~ String

Parameters

NameTypeDescription
stream_inStringstring to match against
replaceStringstring to replace the match with

Return

TypeDescription
Stringreplaced string

Example

re := RegEx->New("\\d+");
result := re->ReplaceAll("order 42 ships on day 7", "NUM");
result->PrintLine();

ReplaceFirst #

Replaces the first occurrence with the given string

method : public : ReplaceFirst(stream_in:String, replace:String) ~ String

Parameters

NameTypeDescription
stream_inStringstring to match against
replaceStringstring to replace the match with

Return

TypeDescription
Stringreplaced string

Example

re := RegEx->New("\\d+");
result := re->ReplaceFirst("order 42 ships on day 7", "NUM");
result->PrintLine();