switch statement, lookup table, or goto instructions.Perl programming language (featuring built-in regex support)sed, awk, and grep POSIX commandsgrep comes from g/re/p, a command in ed to run a run a global regular expression search and print the matched lines)Just like an arithmetic expression \[(5 + 3) \times 4\] is a string built from numbers and operators that evaluates to a numerical value,
a regular expression (regex) is a string built from symbols and special operators like \[
(0 \cup 1) 0^*
\] that evaluates to a language (set of strings).
Most regex tools replace \(\cup\) with |, e.g., (0|1)0*. Use \(\cup\) when handwriting (e.g., on an exam) to avoid confusing | and \(1\).
Operator Precedence
* has highest precedence,We now define both syntax (valid expressions) and semantics (languages they decide) of regexes.
Let \(\Delta = \{ \cup, (, ), *, \emptyset, \emptystring \}\) be the regex control alphabet.
Let \(\Sigma\), the input alphabet, satisfy \(\Sigma \cap \Delta = \emptyset\).
\(R \in (\Sigma \cup \Delta)^*\) is a regular expression deciding language \(L(R) \subseteq \Sigma^*\) if one of the following holds:
This is an inductive definition!
Parentheses can be omitted, in which case the precedence rules apply.
A language \(A\) is regex-decidable if there is a regex \(R\) such that \(L(R) = A\). In Chapter 6 we prove that a language is regex-decidable if and only if it is DFA-decidable.
In the following examples, we assume that \(\Sigma = \{0, 1\}\).
Suppose you’re writing a compiler for a programming language