SubExprMatchCount Property

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


Property Value

The integer number of found sub-expressions. See details in the remarks section.



Read-Only Property Integer
RegExprObj An expression, variable or parameter that specifies a reference to a RegExpr object

Applies To

The property is applied to the following object:

Property Value


If an expression was found and some of its sub-expressions matched, then SubExprMatchCount returns the number of sub-expressions found. To get the position, length and text of a matched sub-expression, use the RegExpr.MatchPos, RegExpr.MatchLen and RegExpr.Match properties correspondingly. For those sub-expressions that were not found these properties return: MatchPos = -1; MatchLen = -1; Match = '';.

If a whole expression was found, but no sub-expressions matched, then SubExprMatchCount returns zero.

If an expression was not found at all, then SubExprMatchCount returns -1.


Suppose we have the following expression: Expression := '(1)?2(3)?';

Let us consider the SubExprMatchCount values for the different input texts:

Input text Exec result Property value Matches
Exec ('123') True SubExprMatchCount=2 Match[0]='123'; Match[1]='1'; Match[2]='3'
Exec ('12') True SubExprMatchCount=1 Match[0]='12'; Match[1]='1'
Exec ('23') True SubExprMatchCount=2 Match[0]='23'; Match[1]=''; Match[2]='3'
Exec ('2') True SubExprMatchCount=0 Match[0]='2'
Exec ('7') False SubExprMatchCount=-1 Match[0]=''

The following sample demonstrates how to use the RegExpr.SubExprMatchCount property to obtain the number of sub-expressions found in the input text.


procedure MatchSample;

  MyRegExpr : OleVariant;
  Input, Expr, ResStr: string;
  MatchCount, i: integer;

  MyRegExpr := HISUtils.RegExpr;
  Input : = 'The ProjectSuite.tcCfgExtender file stores the project suite settings.';
  Expr := '([\w]+)(\.[\w]+)';
  MyRegExpr.Expression : = Expr;
  MatchCount := MyRegExpr.SubExprMatchCount;

  if MatchCount >= 0 then
      for i := 0 to MatchCount do
          ResStr := 'Match[' + aqConvert.IntToStr(i) + '] = ''' + MyRegExpr.Match[i] + '''';


See Also

Using Regular Expressions in Scripts
Using Regular Expressions in Scripts
Exec Method
ModifierStr Property
Match Property
MatchLen Property
MatchPos Property

Highlight search results