Typinator supports powerful Regular Expressions (regex) to create advanced expansions, transformations, and dynamic text automations.
1. Introduction to Regular Expressions in Typinator
Regular expressions allow you to define dynamic text patterns that match and transform input. Typinator uses the ICU Regular Expressions engine, supporting the most commonly used elements such as character classes, groups, assertions, and quantifiers.
Regex is useful for:
- Extracting or restructuring numbers and text
- Validating formats
- Creating conditional expansions
- Using captured groups for dynamic replacements
- Handling repeated or optional text fragments
For a complete documentation of the underlying Regular Expressions package by ICU, see the ICU User Guide. An excellent online tool for learning and testing regular expression can be found at regex101.com.
2. Operators
Operators define how many times elements may repeat.
| Operator | Meaning | Example / Explanation |
|---|---|---|
| |
alternatives | a|b|c = a or b or c |
* |
zero or more times [max] | a* = ε, a, aa, aaa, … (as many as possible) |
+ |
one or more times [max] | a+ = a, aa, aaa, … (as many as possible) |
? |
empty or once [max] | a? = ε, a (prefer a) |
*? |
zero or more times [min] | a*? = ε, a, aa, aaa, … (as few as possible) |
+? |
one or more times [min] | a+? = a, aa, aaa, … (as few as possible) |
?? |
empty or once [min] | a?? = ε, a (prefer ε) |
*+ |
zero or more times [poss] | a*+ = ε, a, aa, aaa, … (as many as possible) |
++ |
one or more times [poss] | a++ = a, aa, aaa, … (as many as possible) |
?+ |
empty or once [poss] | a?+ = ε, a (prefer a) |
|
|
exactly n times | a{5} = aaaaa |
{n,m} |
between n and m times [max] | a{3,5} = aaa, aaaa, aaaaa (prefer aaaaa) |
{n,m}? |
between n and m times [min] | a{3,5}? = aaa, aaaa, aaaaa (prefer aaa) |
{n,m}+ |
between n and m times [poss] | a{3,5}+ = aaa, aaaa, aaaaa (prefer aaaaa) |
{n,} |
at least n times [max] | a{2,} = aa, aaa, aaaa (as many as possi |
ε = empty match (no characters) | [max] = match as many as possible | [min] = match as few as possible | [poss] = “possessive match”, match as many as possible, do not retry alternatives after the first possible match
3. Groups
Groups define logical sections of patterns and allow capturing matched text.
| Pattern | Meaning | Example / Explanation |
|---|---|---|
(p) |
capturing group | Stores matched text as $1, $2, etc. |
(?:p) |
non-capturing group | Group pattern p without capturing as $n. |
(?=p) |
look-ahead assertion | Check whether the following text matches the pattern p. |
(?!p) |
negative look-ahead assertion | Check whether the following text does not match the pattern p. |
(?<=p) |
look-behind assertion | Check whether the previous text matches the pattern p. |
(?<!p) |
negative look-behind assertion | Check whether the previous text does not match the pattern p. |
(?#...) |
comment; Ignored during matching. | (?# ignores everything, from opening to closing parentheses) |
4. Character Sets and Wildcards
| Expression | Meaning | Example / Explanation |
|---|---|---|
. |
any single character | |
.+ |
one or more of any character | |
[...] |
match any character in set | [abc] = a or b or c |
[^...] |
match any character not in set | [^abc] = any character except a, b, or c |
[a-z] |
range of lowercase letters | [0-9a-F] = hexadecimal digit (digits 0 to 9, letters A to F) |
5. Anchors
| Anchor | Meaning | Example / Explanation |
|---|---|---|
^ |
beginning of a line | Irrelevant in Typinator — patterns never extend over multiple lines |
$ |
end of a line | never extend over multiple lines |
\b |
word boundary | \b[aeiou] = Lower-case vowel at beginning of a word |
\B |
not a word boundary | \b[aeiou] = Lower-case vowel following another word character |
6. Special Characters
| Expression | Meaning | Example / Explanation |
|---|---|---|
\s |
whitespace | |
\S |
non-whitespace | |
\d |
digit | |
\D |
non-digit | |
\w |
word character | |
\W |
non-word character | |
\n |
backreference to nth group |
so-called “backward reference” within a pattern (.)-\1 = a-a, #-# (characters before and after “-“ must be the same) |
\ |
treat following character literally | \(.\) = any character, enclosed in parentheses |
\Q...\E |
quoted sequence; treat everything literally | \q([.])\E = ([.]); enclosed characters have no special meaning |
7. Character Classes
Character classes can appear instead of characters in patterns or within character sets.
| Class | Meaning |
|---|---|
[:alpha:] |
letters |
[:upper:] |
uppercase letters |
[:lower:] |
lowercase letters |
[:digit:] |
digits |
[:alnum:] |
letters or digits |
[:blank:] |
space character |
[:xdigit:] |
hexadecimal digit (0-9, A-F, a-f) |
[:punct:] |
punctuation symbol (e.g., . , " ' ? ! ; : # $ % & ( ) * + - |
[:space:] |
whitespace character |
8. Replacement Patterns in Typinator
| Element | Meaning |
|---|---|
$0 |
entire match |
$1, $2… |
captured groups |
\$ |
literal dollar sign |
\\ |
literal backslash |
9. Practical Tips for Using Regex in Typinator
- Use
\Q...\Eto escape long literal sequences. - Use capturing groups when restructuring or reordering text.
- Test your regex on regex101.com before using it in Typinator.
- Prefer explicit ranges like
[0-9]when targeting digits.
10. Examples
Here you can find some simple examples how to use regex in regex sets in Typinator.
Switch two numbers
Pattern: (\d+)\/(\d+)
Replacement: $2/$1Input: 25/100 -> 100/25
Reformat dates
Pattern: (\d{2})\.(\d{2})\.(\d{4})
Replacement: $3-$2-$1Input: 17.12.2025 -> 2025-12-17
Surround typed words
Pattern: \w+
Replacement: #$0#Input: text -> #text#
Normalize prices
Pattern: ([\d+,.]+)\$
Replacement: US$ $1Input: 25$ -> US$ 25
Reformat phone numbers
Pattern: \+?(\d{1,3})[\s-]?(\d{3})[\s-]?(\d{4})
Replacement: +$1 $2 $3Input: 123456789 -> +12 345 6789