Replace Method

Applies to TestComplete 15.64, last modified on June 12, 2024


The RegExpr.Replace method returns the AInputStr string where the text that matches the regular expression is replaced with the AReplaceStr string.


RegExprObj.Replace(AInputStr, AReplaceStr)

RegExprObj An expression, variable or parameter that specifies a reference to a RegExpr object
AInputStr [in]    Required    String    
AReplaceStr [in]    Required    String    
Result String

Applies To

The method is applied to the following object:


The method has the following parameters:


Specifies the input text for the replace operation.


Specifies the text to substitute existing text.

Result Value

The string with substituted text.


Before calling this method you should initialize the regular expression pattern via the Expression property.


This sample code illustrates how to use this method. It extracts the e-mail address and replaces it with the given text.


procedure ReplaceSample;
var MyRegExp, InStr, ResStr;
  MyRegExp := HISUtils.RegExpr;
  InStr := 'If you have any questions, send them to [email protected].';
  ResStr := '';

  // This expression specifies an e-mail address pattern
  MyRegExp.Expression := '[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}';
  ResStr := MyRegExp.Replace(InStr, 'MyCompany support team');
  // Posts the following to the log:
  // If you have any questions, send them to MyCompany support team.

See Also

Using Regular Expressions in Scripts
Using Regular Expressions in Scripts
Expression Property
InputString Property
Exec Method
Substitute Method

Highlight search results