Regular expressions in RanoreXPath | Ranorex
Help CenterUser GuideRegular expressions in RanoreXPath

Regular expressions

A regular expression, regex or regexp (sometimes called a rational expression) is, in theoretical computer science and formal language theory, a sequence of characters that defines a search pattern. Usually, this pattern is then used by string searching algorithms in computer software for “find”, or “find and replace” operations on strings. Ranorex also uses this syntax expressions for matching RanoreXPath definitions.

For more comprehensive documentation of regex, please consult the corresponding MSDN web site:


Example Description
button[@text~’sample[0-9]’] Matches the following button elements: ‘sample0’, ‘sample1’, … ‘sample9’, ‘My sample26’
listitem[@text~’^sample’] Matches all elements starting with text value sample
listitem[@text~’sample$’] Matches all elements ending with text value sample
listitem[@text~’gr(a|e)y’] Matches text value gray or grey
listitem[@text~’^sample 123$’] Matches ‘sample 123’ (use backslash to escape special characters like space)
listitem[@text~’^(?i:MyTeXt)$’] external Matches the regular expression case-insensitive, e.g. ‘mytext’, ‘MYTEXT’, ‘mYTeXT’, …or database containing combinations of usernames and passwords to test

Characters that need to be escaped

The following are special characters that need to be escaped when used in a regular expression by prefixing them with a backslash ”. E.g. when you want to match the text ‘Sample.’ (with a dot at the end), the dot needs to be escaped: ‘Sample.’.

Character Description
. The dot will match any single character. For example ‘Sample.’ matches ‘Sample1’, ‘Samplex’, etc.
$ The dollar sign will match the end of the string. The expression ‘abc$’ will match the sub-string ‘abc’ only if it is at the end of the string.
| The alternation character allows either expression on its side to match the target string. The expression ‘gr(a|e)y’ can match ‘gray’ or ‘grey’.
* The asterisk indicates that the character to the left of the asterisk in the expression should match zero or more times. For example ‘go*gle’ matches ggle, gogle, google, gooogle, etc.
+ The plus is similar to asterisk but there must be at least one match of the character to the left of the + sign in the expression. For example ‘go+gle’ matches gogle, google, gooogle, etc.
? The question mark (?) matches the character to its left 0 or 1 times. For example, ‘colou?r’ matches both color and colour.
^ Beginning of the string. The expression ‘^A’ will match an A only at the beginning of the string.
( ) The parenthesis affects the order of pattern evaluation.
[ ] Brackets enclosing a set of characters indicate that any of the enclosed characters may match the target character.
[^0-9] The caret immediately following the left-bracket has a different meaning. It is used to exclude the remaining characters within brackets from matching the target string. The expression ‘[^0-9]’ indicates that the target character must not be a digit.