MatchPos Property

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


The RegExpr.MatchPos property returns the position 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 first character position of the matching text occurrence in the input string.


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 [email protected] or [email protected]';
  // 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

Using Regular Expressions in Scripts
Using Regular Expressions in Scripts
Exec Method
SubExprMatchCount Property
Match Property
MatchLen Property

Highlight search results