![Wait, forgot to escape a space. Wheeeeee[taptaptap]eeeeee. Regular Expressions comic](https://imgs.xkcd.com/comics/regular_expressions.png)
A Regular Language is a formal language (set of finite strings) that can be built from very simple sets with a small number of allowable operations. Regular languages are interesting because we will show that the language of any DFA (or NFA) is regular, and that every regular language is the language of some DFA (and some NFA).
The collection of all regular (formal) languages is defined as follows:
Here are some examples of regular languages, assuming :
Every regular language has a finite description (in terms of union, concatantion, and star) of singleton sets. However, writing all the curly braces rapidly grows tedious. Therefore, we will use a shorthand for describing a regular set, called a regular expression.
Regular expressions are formulas, define as follows:
As we did with logical formulas, we will almost always write regular expressions with a more relaxed approach to parentheses than the official definition suggests. In terms of precedence, star binds more tightly than concatenation, which binds more tightly than the vertical bar, so, e.g., means .
Here are some regular expressions, assuming :
Concatenation binds more tightly than choice, so this means
Star binds more tightly than concatenation, so this means .
Concatenation binds more tightly than choice, so this means
Star binds more tightly than concatenation, so this means .
In terms of where the implicit parentheses are, there is a strong analogy between
So means , just as means .
Given a regular expression , we denote the language of by , defined as follows:
We say that a string matches if .
The languages of the regular expressions in the previous Example are exactly the regular sets in the Example before that. That is,