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 notationMath notationMeaning
A | B, , or Logical OR (alternation), set union
ABConcatenation
A*Kleene star (zero or more occurrences)
A+one or more occurrences
A?zero or one occurrences

Metacharacters

MetacharacterMatch
^begin line
$end line
Any character

Precedence

The precedence of regular expression, from high to low, are

  1. Closure (Kleene star) a*
  2. Concatenation ab
  3. Alternation a|b