Exec Method

Applies to TestComplete 15.65, last modified on June 25, 2024


The RegExpr.Exec method searches the InputStr for the nearest occurrence of text that matches the regular expression pattern specified by the Expression property. To get a portion of the text that matches the pattern, use the Match property.



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

Applies To

The method is applied to the following object:


The method has the following parameter:


Specifies the text that a regular expression is applied to.

Result Value

Returns True if the text matching the expression was found and False otherwise.


You should initialize the Expression property with the regular expression before calling the Exec method, otherwise an error occurs.

A call to this method also assigns the value of the InputStr parameter to the InputString property.

This method has two versions: ExecNext and ExecPos that can be applied if both Expression and InputString have been initialized.


This sample code illustrates how to use the regular expressions. It extracts e-mail addresses from the input string.


procedure ExecSample;
  MyRegExp: OleVariant;
  ResStr: String;

  //This expression specifies an e-mail address pattern
  if MyRegExp.Exec('Please e-mail us at [email protected] or [email protected]') then
      ResStr := ResStr + MyRegExp.Match[0] + '; ';
    Until not MyRegExp.ExecNext;
  Log.Message('These e-mails were extracted: '+ResStr);
  //Posts the following to the log:
  //'These e-mails were extracted: [email protected]; [email protected]; '

See Also

Using Regular Expressions in Scripts
Using Regular Expressions in Scripts
Expression Property
InputString Property
Match Property
ExecNext Method
ExecPos Method

Highlight search results