Regular expression is a sequence of characters that represents patterns of strings.
In strict computer-science sense, regular expression formalize regular language, and are equivalent to finite automata. However, modern regex engines often include additional features.
Use regex101 to build and debug regex.
Subsections
Table
Operations
| Posix notation | Math notation | Meaning |
|---|---|---|
A | B | Logical OR (alternation), set union | |
AB | Concatenation | |
A* | Kleene star (zero or more occurrences) | |
A+ | one or more occurrences | |
A? | zero or one occurrences |
Metacharacters
| Metacharacter | Match |
|---|---|
^ | begin line |
$ | end line |
| Any character |
Precedence
The precedence of regular expression, from high to low, are
- Closure (Kleene star)
a* - Concatenation
ab - Alternation
a|b