1. Summary Description
A regular expression is a way to describe a language using a string of symbols and operators. While a Finite Automaton (DFA/NFA) represents a language through its computational process, a regular expression represents the same language through its structural definition.
2. Formal Definition
A value R is a regular expression if it is one of the following:
- for some (a single character from the alphabet).
- : Empty String
- : Empty Set
- , where and are regular expressions (Union).
- , where and are regular expressions (Concatenation).
- , where is a regular expression (Star operation).
Common Confusion between and
represents the language containing a single string the empty string
represents the language that doesn’t contain any strings
Shorthand Notations
For convenience, there are some notations expressed as followed:
- : shorthand expression for , all strings that are or more concatenations of strings from
- : shorthand for the concatenation of with each other
- : the language of , distinguishing a regular expression and the language it describes
3. Regular Operations
Regular expressions are built using three fundamental operations:
- Union (): Corresponds to the logical “OR”
- describes the language .
- Concatenation (): Joining strings together.
- Often the symbol is omitted
- instead of
- Star (): Represents zero or more repetitions of the preceding expression.
- describes the language .
4. Precedence of Operations
To avoid excessive parentheses, the operations follow a specific order of precedence:
- Star (∗) has the highest precedence.
- Concatenation (∘) is next.
- Union (∪) has the lowest precedence.
5. Identities
If we let be any regular expression
Adding the empty language to any other language will not change it
$R \circ \epsilon = R$
Joining the empty string to any string will not change it
However, exchanging and in the preceding identities may cause the equalities to fail
If , then but
$R \circ \emptyset \text{ may not equal } R$
If $R = 0$, then $L(R) = \{ 0 \}$ but $L(R \circ \emptyset) = \emptyset$
Equivalence with Finite Automata
One of the most important results in formal language theory is that Regular Expressions and Finite Automata are equivalent in power.
- Theorem: A language is regular if and only if some regular expression describes it.
- Implication: For any regular expression, you can build an NFA that recognizes the same language, and for any DFA, you can write a regular expression that describes its language.
Comparison of Representations
| Feature | Finite Automata (DFA/NFA) | Regular Expression |
|---|---|---|
| Perspective | Computational (How to process) | Structural (What it looks like) |
| Best Use | Implementing search in hardware/code | Writing search queries and patterns |
| Power | Recognizes Regular Languages | Describes Regular Languages |