Replace Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

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

Declaration

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:

Parameters

The method has the following parameters:

AInputStr

Specifies the input text for the replace operation.

AReplaceStr

Specifies the text to substitute existing text.

Result Value

The string with substituted text.

Remarks

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

Example

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

DelphiScript

procedure ReplaceSample;
var MyRegExp, InStr, ResStr;
begin
  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');
  Log.Message(ResStr);
  // Posts the following to the log:
  // If you have any questions, send them to MyCompany support team.
end;

See Also

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

Highlight search results