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 escapingSome 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| Element | Meaning | Example | Accepts |
| ^ | start of the string | ^ABC | strings that start with "ABC" |
| $ | end of the string | XYZ$ | strings that end with "XYZ" |
| ^ ... $ | exact match (start and end) | ^SECRET$ | only the string "SECRET" |
| . | any single character | AB.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 times | ABC* | "AB", "ABC", "ABCC", ... |
| + | previous item, 1 or more times | ABC+ | "ABC", "ABCC", ... |
| ? | previous item, 0 or 1 time | ABC? | "AB" or "ABC" |
| {n} | exactly n times | C{3} | "CCC" |
| {n,} | at least n times | C{5,} | 5 or more "C" |
| {n,m} | between n and m times | ABC{3,5} | "AB" followed by 3-5 "C" |
| {0,m} | up to m times | C{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 explainedHere is a more detailed look at each element, with examples.
Basic useIf 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".
WildcardsThe 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 charactersUse round brackets
( and
) to define sequences of characters that belong together.
This is especially useful together with the repetition codes (see below).
The OR operatorThe
| 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.
ExamplesRemember to add
^ at the start and
$ at the end if nothing else should be allowed before or after your code.
| Expression | Accepts |
| ^ABC | any 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 expressionBefore using an expression in ConfTool, test it with an online regular expression tester:
More information