ExecNext Method

Applies to TestComplete 15.40, last modified on July 05, 2022

Description

The RegExpr.ExecNext method searches the input string for the next text occurrence that matches the regular expression pattern. To get a portion of the text that matches the pattern, use the Match property.

Declaration

RegExprObj.ExecNext()

RegExprObj An expression, variable or parameter that specifies a reference to a RegExpr object
Result Boolean

Applies To

The method is applied to the following object:

Result Value

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

Remarks

You should initialize the Expression property with the regular expression and the InputString property (explicitly or implicitly via previous Exec call) with input string before calling the ExecNext method, otherwise an error occurs.

Example

The following example demonstrates how to use the RegExpr.ExecNext method to iterate through the input text untill all matches are found.

DelphiScript

procedure ExecSample;
var
  MyRegExp: OleVariant;
  ResStr: String;
begin
  MyRegExp:=HISUtils.RegExpr;
  ResStr:='';

  //This expression specifies an e-mail address pattern
  MyRegExp.Expression:='[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}';
  if MyRegExp.Exec('Please e-mail us at [email protected] or [email protected]') then
    Repeat
      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]; '
end;

See Also

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

Highlight search results