The function RegExSplit looks for a match to the pattern specified by aExpression in the string aInput, and returns the matched characters in the TStringList aPieces - depending on the value specified by aExpression.

Where the pattern matches, a boolean True value will be returned indicating that a match was found. False will be returned where no match was found.

Declaration: Function RegExSplit(const aExpression, aInput: String; aPieces : TStringList): boolean;

Several examples follow.

procedure ScriptEvent(var Value:Variant);
var
Str1, Str2 : string;
MyOut1 : TStringList;
Int6 := integer;
begin
Str1 := 'a';
Str2 := 'banana';
MyOut1 := TStringList.create;
 
//Returns TRUE - MyOut output string list contains three items
//"a", "a", and "a" being the 3 matches when the pattern is repeated across the entire string
RegExSplit(Str1, Str2, MyOut1);
For Int6 := 0 to MyOut1.count-1 do
Loginfo(MyOut1[Int6]);
LogInfo('');
//Returns TRUE - MyOut output string list contains three items
//"a", "a", and "a" being the 3 matches when the pattern is repeated across the entire string
MyOut1.clear;
If RegExSplit('a','banana',MyOut1) then
LogInfo('Yes!')
else
LogInfo('No . . . ');
MyOut1.clear;
RegExSplit('a','banana', MyOut1);
For Int6 := 0 to MyOut1.count-1 do
Loginfo(MyOut1[Int6]);
LogInfo('');
 
MyOut1.clear;
//Returns TRUE and MyOut string list contains two items: single digits "6" and "6"
RegExSplit('\d','Route 66',MyOut1)
For Int6 := 0 to MyOut1.count-1 do
Loginfo(MyOut1[Int6]);
LogInfo('');
 
MyOut1.clear;
//Pattern "\d+" matches 1 or more consecutive digits
//Function returns TRUE and sets MyOut output string list to "66"
RegExSplit('\d+','Route 66',MyOut1)
For Int6 := 0 to MyOut1.count-1 do
Loginfo(MyOut1[Int6]);
LogInfo('');
 
MyOut1.clear;
//Returns TRUE and output string list MyOut contains "555", "123", and "456"
//YES, even "456" - because there are 3 consecutive digits at that point in the string
RegExSplit('\d{3}','+1-555-123-4567',MyOut1)
For Int6 := 0 to MyOut1.count-1 do
Loginfo(MyOut1[Int6]);
LogInfo('');
end;