Match Property

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

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

Declaration

RegExprObj.Match(Index)

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:

Parameters

The property has the following parameter:

Index

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

Property Value

A string that contains the matching text.

Remarks

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

Example

The following code obtains the text that matches a regular expression and posts the text to the test log.

DelphiScript

procedure Sample;
var
  MyRegExpr : OleVariant;
begin
  MyRegExpr := HISUtils.RegExpr;
  MyRegExpr.InputString := 'Please e-mail us at [email protected] or [email protected]';
  MyRegExpr.Expression := '[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}';
  MyRegExpr.ExecPos;
  // Posts the first matching segment of the text to the test log
  Log.Message(MyRegExpr.Match[0]);
end;

See Also

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

Highlight search results