Topic: How to use regular expressions

ConfTool Pro has several functions in which you can use regular expressions to validate the data that users enter. They are used to:

This page gives a short overview of how to define these expressions. Regular expressions can be powerful and complex, but for use in ConfTool they are usually simple to create.

This information is also available in German.

Tip: If you only use ordinary letters (A-Z, a-z) and digits (0-9), you can ignore all the special characters below and simply type your code.
 
Special characters and escaping
Some symbols have a special meaning (they are called meta characters): . ^ $ * + ? ( ) [ ] { } | \ /.
To match such a symbol literally, put a backslash \ in front of it - for example \. matches a real dot.
 
Quick reference
ElementMeaningExampleAccepts
^start of the string^ABCstrings that start with "ABC"
$end of the stringXYZ$strings that end with "XYZ"
^ ... $exact match (start and end)^SECRET$only the string "SECRET"
.any single characterAB.YZ"ABAYZ", "ABaYZ", "AB0YZ", ...
[a-z]any one character from the range[a-z] [A-Z] [0-9] [a-c]one letter or digit from the given range
( )group characters together(ABC)+"ABC", "ABCABC", ...
|OR(ABC|XYZ)"ABC" or "XYZ"
*previous item, 0 or more timesABC*"AB", "ABC", "ABCC", ...
+previous item, 1 or more timesABC+"ABC", "ABCC", ...
?previous item, 0 or 1 timeABC?"AB" or "ABC"
{n}exactly n timesC{3}"CCC"
{n,}at least n timesC{5,}5 or more "C"
{n,m}between n and m timesABC{3,5}"AB" followed by 3-5 "C"
{0,m}up to m timesC{0,5}0 to 5 "C"

Note: For "up to m" use {0,m}. The short form {,m} (empty lower bound) is non-standard and may be treated as literal text by ConfTool's regex engine (PCRE2).
Quantifiers also work on groups and character sets, e.g. [A-Z]{5,} accepts any string of at least 5 letters A-Z.
 
The elements explained
Here is a more detailed look at each element, with examples.
 
Basic use
If you simply enter a text into the code field (where you define the regular expression), all strings that include this code are accepted.
Note that the codes are case-sensitive, so "a" and "A" are two different characters.

To make sure a string starts with your code, add ^ at the start.
Example: ^ABC accepts all strings that start with "ABC".
To make sure a string ends with your code, add $ at the end.
Example: XYZ$ accepts all strings that end with "XYZ".
To allow only strings that match your code exactly, add ^ at the start and $ at the end.
Example: ^SECRET$ accepts only the string "SECRET".
 
Wildcards
The symbol . stands for any single character, so any character the author/participant enters is accepted.
Example: AB.YZ accepts "ABAYZ", "ABaYZ", "AB0YZ", and so on.
[a-z] stands for any character from a to z, [A-Z] for the capital equivalent and [0-9] for any digit.
You can also use sub-ranges, e.g. [a-c] to accept only the characters "a" to "c".
 
Grouping: sequences of characters
Use round brackets ( and ) to define sequences of characters that belong together.
This is especially useful together with the repetition codes (see below).
 
The OR operator
The | symbol works as an "OR": it accepts the part before it or the part after it.
Example: (ABC|XYZ) accepts the string "ABC" or "XYZ".
 
Repetition (quantifiers)
Several codes define how often the character or sequence before them may be repeated.
* allows any number of repetitions (0 to unlimited).
Example: ABC* accepts "AB" and any number of following "C" (0 or more).
+ is similar to *, but requires at least one repetition.
Example: ABC+ accepts "ABC" and any number of additional "C".
? means zero or one occurrence of the preceding character or sequence.
Example: ABC? accepts "AB" or "ABC".
For fixed counts and ranges (e.g. "exactly 3" or "3 to 5"), use the { } codes shown in the Quick reference above.
 
Examples
Remember to add ^ at the start and $ at the end if nothing else should be allowed before or after your code.
ExpressionAccepts
^ABCany string that starts with "ABC"
XYZ$any string that ends with "XYZ"
^SECRET$exactly the string "SECRET"
^[A-Z]{5,}$at least 5 letters A-Z and nothing else
^ABC[0-9]{1,5}$"ABC" followed by 1 to 5 digits, and nothing else

Test your expression
Before using an expression in ConfTool, test it with an online regular expression tester:

More information