The function RegExExtract looks for a match to the pattern specified by aExpression in the string aInput, and returns the matched characters in the variable aPiece - 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 RegExExtract(const aExpression, aInput: String; var aPiece : String): boolean;

Several examples follow.

procedure ScriptEvent(var Value:Variant);
var
Str1, Str2, MyOut : string;
begin
Str1 := 'n';
Str2 := 'banana';
 
//Returns TRUE and MyOut variable is set to "n" to show what has been matched
RegExExtract(Str1, Str2, MyOut);
LogInfo(MyOut);
 
//Returns TRUE and MyOut variable is set to "a" to show what has been matched
RegExExtract('a','banana', MyOut);
LogInfo(MyOut);
If RegExExtract('a','banana',MyOut) then
LogInfo('Yes!')
else
LogInfo('No . . . ');
 
//Returns TRUE and sets MyOut variable to "6" (i.e. the first digit)
RegExExtract('\d','Route 66',MyOut)
LogInfo(MyOut);
 
//Pattern "\d+" matches 1 or more consecutive digits
//Function returns TRUE and sets MyOut variable to "66"
RegExExtract('\d+','Route 66',MyOut)
LogInfo(MyOut);
 
//Returns TRUE and sets MyOut variable to "555"
RegExExtract('\d{3}','+1-555-123-4567',MyOut)
LogInfo(MyOut);
end;