MatchLen Property

Applies to TestComplete 14.72, last modified on January 20, 2021


The RegExpr.MatchLen property returns the length of the text that matches a regular expression or its sub-expression. The index specifies whether the text suits a whole expression or only a sub-expression. The total number of found sub-expressions is specified by the SubExprMatchCount property.



Read-Only Property String
RegExprObj An expression, variable or parameter that specifies a reference to a RegExpr object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:


The property has the following parameter:


Specifies the item’s index. The text that matches the whole expression has an index of 0, part of the text that matches the first sub-expression - 1, and so on.

Property Value

The length of the matching text.


If the specified index does not exist or the sub-expression was not found this property returns -1.


The following example demonstrates how you can use the RegExpr.MatchLen and RegExpr.MatchPos properties to obtain the length and position of the matching text.


procedure MatchSample;

  MyRegExpr : OleVariant;
  Input, Expr, ResStr, Info : string;
  MyRegExpr := HISUtils.RegExpr;
  Input : = 'Please e-mail us at or';
  // Specifies an e-mail address pattern
  Expr := '[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}';
  MyRegExpr.Expression : = Expr;

  if MyRegExpr.Exec(Input) then
          // Posts the matching text, its length and position in the input text to the test log
          Info := '';
          ResStr := MyRegExpr.Match[0];
          Info := 'A match is found at position ' + aqConvert.IntToStr(MyRegExpr.MatchPos[0]);
          Info := Info + #13 + 'The matching fragment length is ' + aqConvert.IntToStr(MyRegExpr.MatchLen[0]);
          Log.Message(ResStr, Info);
      until not MyRegExpr.ExecNext;


See Also

Regular Expressions Syntax
Using Regular Expressions in Scripts
Exec Method
SubExprMatchCount Property
Match Property
MatchPos Property

Highlight search results