Skip to content

RegExReplace ​

The function RegExReplace looks for a match to the pattern specified by ARegExpr in the string AInputStr, and replaces it with the string specified by AReplaceStr.

Where the pattern matches and a successful replacement has been made, a boolean True value will be returned indicating that the string AInputStr has been amended as specified. Where a replacement was not successfully achieved, then a False will be returned.

Declaration: Function RegExReplace( const ARegExpr, AInputStr, AReplaceStr : string) : boolean;

Examples follow.

pascal
procedure ScriptEvent(var Value:Variant);
var
  Str1, Str2, Str3 : string;
begin
  Str1 := 'o';
  Str2 := 'scotties';
  Str3 := 'i'

 //Returns True (successful)
 If RegExReplace(Str1,Str2, Str3) then
     LogInfo('Replacement successful!')
 else
    LogInfo('No, the replacement did not work . . . ');

 If RegExReplace('a','banana','e') then
    LogInfo('Replacement successful!')
 else
    LogInfo('No, the replacement did not work . . . ');

 //Returns false (unsuccessful)
  Str1 := '7';
 If RegExReplace(Str1,Str2,'y') then
    LogInfo('Replacement successful!')
 else
    LogInfo('No, the replacement did not work . . . ');

end;