Applies to TestLeft 4.20, last modified on September 11, 2019

TestLeft supports regular expressions in the "regexp:pattern" format, for example, "regexp:gr[ae]y". You can use regular expressions in –

  • search patterns,
  • test object methods and properties (ClickItem, WaitProperty, wItem and others).

TestLeft regular expressions support the following tokens:

Token Description
^ Matches the beginning of a line. For example, the ^a matches all lines that start with a.
$ Matches the end of a line. For example, the a$ matches all lines that end with a.
. Matches any single character. For example, a.c matches abc, adc, aec but not aaac or ac.
* Indicates that the preceding character or group matches 0 or more times. For example, the abc*d pattern matches abd, abcd, abccd, but not a or abcx. The .* pattern matches a string of any length (including the empty string) that does not contain the newline symbol.

Note that this token is greedy, that is, it matches the longest possible string. For example, when searching on the string abbbb, ab* matches abbbb rather than ab.

+ Indicates that the preceding character or group matches 1 or more times. For example, the ab+d pattern matches abbd or abbbd, but does not match abcd or abbcd.

Note that this token is greedy, that is, it matches the longest possible string. For example, when searching on the string abbbb, ab+ matches abbbb rather than ab or abb.

? Indicates that the preceding character or group is optional, that is, it should either match once or not to match at all. For example, abc?d will find abd and abcd, but not abccd.

Note that this token is greedy, that is, it matches the longest possible string. For example, when searching on the string abc, ab? matches ab rather than a.

??, +?, *? These tokens are non-greedy versions of ?, + and *. That is, they match the shortest possible string. For example, when searching on the string abbbb, ab*? matches a rather than ab or abbbb.
[ ] Matches any single character specified in brackets. For example, d[ab]e matches dae or dbe and does not match dwe or dxe. To include the ] character into the search, make it either first, or last character in the range or use \]. For example, []abc], [abc]] or [ab\]cd].
[^ ] Matches any single character except for those in brackets. For example, d[^bc]e matches dae or dxe, but not dbe or dce. d[^b-d]e matches dae, but not dbe, dce or dde.
[a-b] Matches any single character from a to b, inclusive. For example, d[k-x]e matches dke, dme and dxe, but not dze. To include the - character into the search, make it either first, or last character in the range or use \-. For example, [-ab], [abc-] or [a\-z].
[^a-b] Matches any single character not in the range a through b. For example, a[^k-x]z matches abz, aiz and ayz, but not akz.
a|b Matches either the a or b character or a group. For example, A|abc matches Abc and abc, but not A. The htm|(ml) pattern matches htm and html, but not htl or ml.
a!b Matches a not followed by b. For example, colo!ur matches color, but not colour.
( ) Groups characters. For example, (ab)+ matches ab and abab but not acb.

To specify the ( and ) characters literally, use \( and \).

{ } Indicates a match group. You can use braces in regular expressions that retrieve values that match the expression in the braces. If you create the following regular expression: [0-9]+-[0-9]+, it will match 125-125, but not 125-abcd. However, you can use braces to reduce the size of a regular expression. For example, you may need to modify the expression above to make it find strings containing only similar numbers that are hyphenated. For this purpose, you can specify the first part as a group and then address the value that matches this part by a zero-based index of the match group. This is the index that is specified after the backslash, \n. For example, you can change the regular expression mentioned above in the following way {[0-9]+}-\0. This means that TestLeft will replace the \0 expression with the string returned by the first match group. It will match 168-168, but not 125-168.

To specify the { and } characters literally, use \{ and \}.

\ Escapes special characters: the next character token (?, !, *, - and others) will be treated literally. For example, \$10 matches the string $10. To match a backslash itself, use the double backslash pattern (\\).

When followed by a number n, it matches the nth match group (starting from 0).

\a Matches any alphanumeric character. Same as [A-Za-z0-9].
\b Matches a whitespace character. Same as [ \\t].
\c Matches any alphabetic character. Same as [A-Za-z].
\d Matches any decimal digit. Same as [0-9].
\h Matches any hexadecimal digit. Same as [0-9A-Fa-f].
\n Matches a new line. Same as \r|(\r?\n).
\q Matches a quoted string. Same as ("[^"]*")|('[^']*').
\w Matches a word. Same as [a-zA-Z]+ or \c+.
\z Matches an integer number. Same as [0-9]+ or \d+.

See Also

Understanding Object Identification

Highlight search results