This article provides a list of basic regex metacharacters and illustrates the basic syntax of regexes through example strings.
Ranorex Studio uses the .NET regex engine. This engine is powerful and complex, so this guide focuses on essential elements. For more in-depth information, refer to theofficial .NET documentation.
Metacharacters are characters that act as operators in a regex. To treat a metacharacter as a normal character (for example, to find an actual question mark in a string), you must escape it by placing a backslash before it (\?).
.
The period is a placeholder for any single character
^
Matches the start of a string
$
Matches the end of a string
|
Functions as an either-or operator
?
Matches the preceding element zero or one-time
+
Matches the preceding element one or more times
*
Matches the preceding element zero or more times
{ }
Matches the preceding element the specified number of times
( )
Defines a subexpression
[ ]
Defines a bracket expression that may contain a set of characters that other metacharacters can be applied to
Examples
Single-element expressions
Regex Pattern
Description
Matches
Does Not Match
[1234567]
Matches a single character contained in the bracket expression.
Any single number from 1 to 7.
Any number outside the range (e.g., 8, 9) or multi-digit numbers.
[Max]
Matches any single letter contained in the brackets.
The single letters "M", "a", or "x".
The complete word "Max" or any other letters.
[1-35-8]
Matches a single character within the specified ranges (1-3 and 5-8).
The numbers 1, 2, 3, 5, 6, 7, 8.
The number 35, the number 4, or any other characters.
Multi-element expressions
Regex Pattern
Description
Matches
Does Not Match
[1-9][ab]
Combines two bracket expressions to find pairs of characters.
Any combination like "1a", "1b", "2a", up to "9b".
Single characters like "1" or "a", or reversed pairs like "a1".
Quantifiers
The quantifier metacharacters ?, +, *, and {} are placed after the characters they should apply to.
Regex Pattern
Description
Matches
Does Not Match
[1-9]?
Matches the preceding element zero or one time.
An empty string or a single digit (1-9).
Multiple digits like "12".
(Colou?r)
Makes the "u" optional.
Both "Colour" and "Color".
"Colouur".
[1-9]+
Matches the preceding element one or more times.
Any number greater than 0 (for example, "5", "123").
An empty string or "0".
[0-9]{5}
Matches the element exactly the specified number of times.
Any five-digit number (for example, "12345").
Numbers with four or six digits.
[0-9]{3,}
Matches the element at least the specified number of times.
Any number with three or more digits.
Numbers with only one or two digits.
[0-9]{3,5}
Matches a specific range of repetitions.
Numbers with 3, 4, or 5 digits.
Numbers with 2 digits or 6+ digits.
Match the beginning of a string
Regex Pattern
Description
Matches
Does Not Match
^Image_
The ^ anchor forces the match to start at the beginning.
Strings starting with "Image_".
"New_Image_" or "image_".
(^Image_)[0-9]{3}
Combines the start anchor with a specific digit count.
"Image_001", "Image_999", etc.
"Image_1" or "Image_1234".
(^Image_)[0-9]{3}(.jpg)
Uses a backslash to escape the period metacharacter.
"Image_123.jpg".
"Image_123jpg" or "Image_123.png".
Match end of string
Regex Pattern
Description
Matches
Does Not Match
Sample$
The $ anchor forces the match at the end of the string.
Strings ending in "Sample".
"Sample_1" or "Samples".
(Sample[0-9]{3}$)
Matches "Sample" followed by three digits at the very end.
"Sample123" (at end of line).
"Sample12" or "Sample1234".
Placeholders
Regex Pattern
Description
Matches
Does Not Match
Image.*
Matches all strings that consist of “Image” followed by any number of other characters.