Token | Description |
---|---|
^ | Matches the beginning of a line. For instance, the ^a search pattern lets you find all lines that start with a. |
$ | Matches the end of a line. For instance, the a$ search pattern lets you find all lines that end with a. |
. | Matches any single character. For example, a.c matches abc, adc, aec but not aaac or abbc. |
* | Indicates that the preceding character or group matches 0 or more times. For instance, 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 aab.
|
+ | Indicates that the preceding character or group matches 1 or more times. For instance, the ab+d pattern matches abbd or abbbd, but does not match abcd orabbcd.
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 thanab 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 instance, 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 instance, d[^bc]e matches dae or dxe, but not dbe or dce. d[^b-d]e matches dae, but not dbe, dceor dde. |
[a-b] | Matches any single character from a to b, inclusive. For instance 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 instance 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 a round bracket that should be treated literally, precede it with a backslash: \( or \).
|
{ } | 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 TestComplete 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 a brace that should be treated literally, precede it with a backslash: \{ or \}.
|
\ | A backslash indicates that the next character token (such as ?, !, *, - and others) should 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 (for example, \0), indicates the match group at the specified index (from 0).
|
![]() |
In JScript, C++Script and C#Script, you should use double backslashes to interpret the subsequent special character literally: "\\?", "\\.", "\\2" and so on. To match a backslash character, use the "\\\\" pattern.
|
\a | Matches any alphanumeric character. This token is equivalent to [A-Za-z0-9]. |
\b | Matches a whitespace character. |
\c | Matches any alphabetic character. This token is equivalent to [A-Za-z]. |
\d | Matches any decimal digit. This token is equivalent to [0-9]. |
\h | Matches any hexadecimal digit. This token is equivalent to [0-9A-Fa-f]. |
\n | Matches a new line character. |
\q | Matches a quoted string. This token is equivalent to ("[^"]*")|('[^']*'). |
\w | Matches a word. This token is equivalent to [a-zA-Z]+ or \c+. |
\z | Matches an integer number. This token is equivalent to [0-9]+ or \d+. |
Monday, October 28, 2013
Regular Expression Token in QTP
Subscribe to:
Posts (Atom)