Bundle Regular expression matching and replacement. RegEx compiles a pattern once and supports full match, substring search, capture groups, and global replacement. Included in lang.obl.
RegEx
Regular expression engine.
Support for following patterns:
- any ‐ .
- optional ‐ ?
- zero or more repetitions ‐ *
- one or more repetitions ‐ +
- first single match ‐ ^
- last single match ‐ $
- (one|two|three) ‐ group
- [start-end] ‐ range
Support for following special groups:
- word ‐ \w
- not word ‐ \W
- digit ‐ \d
- not digit ‐ \D
- white space ‐ \s
- not white space ‐ \S
- repeat ‐ {least, most}
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 occurrences
method : public : Find(stream_in:String) ~ Vector<Result>Parameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | string to match against |
Return
| Type | Description |
|---|---|
| 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) ~ ResultParameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | string to match against |
Return
| Type | Description |
|---|---|
| Result | matched 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() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true 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) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | string to match against |
Return
| Type | Description |
|---|---|
| String | matched 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) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | string to match against |
| offset | Int | offset into the to match against |
Return
| Type | Description |
|---|---|
| String | matched 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) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | string to match against |
Return
| Type | Description |
|---|---|
| Bool | true 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
| Name | Type | Description |
|---|---|---|
| stream_in | String | regex 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) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | string to match against |
| replace | String | string to replace the match with |
Return
| Type | Description |
|---|---|
| String | replaced 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) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | string to match against |
| replace | String | string to replace the match with |
Return
| Type | Description |
|---|---|
| String | replaced string |
Example
re := RegEx->New("\\d+");
result := re->ReplaceFirst("order 42 ships on day 7", "NUM");
result->PrintLine();