Applies to TestComplete 14.40, last modified on May 21, 2020

Description

The RegExpr object allows using regular expressions in DelphiScript. This way, you can perform search and replace operations over the text fragments that match the specified regular expression pattern. Also, you can use regular expressions to validate user input data.

To get the object in your tests, use the HISUtils.RegExpr property.

Please read the Regular Expressions Syntax topic to learn how to compose regular expressions.

Requirements

The RegExpr object is available only if the HISUtils plugin is enabled.

This plugin is installed and enabled by default during the TestComplete installation. You can check the plugin status in the File > Install Extensions dialog in TestComplete. You can find the plugin in the Common group.

Members

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 support@mycompany.com or sales@mycompany.com';
  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

HISUtils Object
Installing Extensions
Using Regular Expressions in Scripts
Regular Expressions Syntax

Highlight search results