Hello! Welcome to the next stage of our journey into the Theory of Computation.
In the previous module, we focused on finite automata (DFAs and NFAs) as machines that recognize languages. We saw how they process strings and decide whether to accept or reject them. Now, we are going to explore a different, but equally powerful, way to handle regular languages: a notation for describing them.
You have likely used this notation in your software development work, particularly with tools like grep or libraries such as Python's re module or JavaScript's RegExp objects. We are talking about regular expressions. While you may be familiar with their practical application for pattern matching, this lesson will formalize their definition and explore the theoretical underpinnings.
Our learning outcome for this lesson is to: Define regular expressions and their corresponding language semantics (union, concatenation, Kleene star). We will build them from the ground up, starting with the fundamental operations that combine languages.
1. The Building Blocks: Regular Operations on Languages
Before we can define regular expressions, we must first understand the three fundamental operations they use to construct languages. These are operations that take one or two languages (which are sets of strings) and produce a new language.
The following video from MIT OpenCourseWare introduces these three "regular operations."
1. Introduction, Finite Automata, Regular Expressions
Watch this segment to get an overview of the three regular operations: union, concatenation, and star. The examples provided will help build an intuitive understanding.
Watch from 33:32 to 38:17. Focus on how each operation (Union, Concatenation, and Star) is defined and the examples given for each.
Let's formalize these definitions. For the following, let and be two languages.
-
Union: The union of and , written , is the set of strings that are in , or in , or in both. This is the standard set union operation you're familiar with.
-
Concatenation: The concatenation of and , written or simply , is the set of strings that can be formed by taking any string from and appending any string from to it.
For example, if and , then . Note that concatenation is not commutative; in general, .
-
Kleene Star (or Kleene Closure): The Kleene star of a language , written , is the set of all strings formed by concatenating zero or more strings from .
Here, (the language containing only the empty string), , and for . The inclusion of is crucial: the empty string is always a member of , regardless of the language .
The Kleene star can be the trickiest to grasp. The image below provides a clear, step-by-step example.

For a concise summary of these operations, you can review the first page of the following lecture notes.
These notes from the University of Illinois provide crisp, formal definitions of the three regular operations on languages.
Read the first page, focusing on the sections 'Concatenation of Languages' and 'Kleene Closure'. The examples provided are very helpful.
2. Formal Definition of a Regular Expression
Now that we have the operations, we can formally define what a regular expression is. The definition is recursive, much like definitions for data structures or language grammars you've encountered in computer science.
A regular expression is defined as follows:
-
Base Cases (Atomic Expressions):
- is a regular expression.
- is a regular expression.
- is a regular expression for any symbol (where is the alphabet).
-
Inductive Steps (Compound Expressions): If and are regular expressions, then the following are also regular expressions:
- (Union)
- (Concatenation)
- (Kleene Star)
Each regular expression describes or generates a language, which we denote as . The semantics, or meaning, of a regular expression is the language it corresponds to.
The "Syntax and Semantics" table in the following resource provides a perfect, formal mapping from the expression (syntax) to the language it represents (semantics).
This resource provides the formal inductive definition of a regular expression, clearly separating the syntax (the formula) from the semantics (the language it describes).
Read the section 'Regular Expressions' on page 2. Pay close attention to the table 'Regular Expressions Formal Inductive Definition'. This is the core definition for this lesson.
Notational Conventions
To make regular expressions easier to read and write, we use a few conventions:
- Operator Precedence: The star operator has the highest precedence, followed by concatenation, and then union. This is similar to how multiplication has precedence over addition in arithmetic.
- For example, is parsed as .
- Omitting Concatenation: The concatenation operator is often omitted, just like the multiplication sign in algebra.
- For example, is usually written as just . So, means .
- Alternative Union Symbol: In many programming contexts and some textbooks, the union operator is written as
|or+. We will primarily use .
3. Examples: From Syntax to Semantics
Let's see these definitions in action. The power of regular expressions comes from combining the basic elements to describe complex patterns.
Let .
-
The regular expression **
** describes the language of all strings that contain exactly one '1'.- This results in strings like
1,01,10,00100, etc.
-
The regular expression **
** describes the language of all binary strings that contain00as a substring.- describes any binary string.
- So this expression describes: (any string), followed by
00, followed by (any string).
-
The regular expression **
** describes the language of strings with alternating 0s and 1s, but only those that start and end with the same character (or are empty).- gives
ε,10,1010, ... - gives
ε,01,0101, ...
- gives
The following resources provide more excellent examples.
These lecture slides from Stanford offer a wealth of examples that are great for building intuition. They clearly show how to combine the basic operators to create meaningful patterns.
Review the slides under the headings 'Regular Expression Examples' and 'Regular Expressions are Awesome'. These examples illustrate how compact expressions can describe interesting and infinite languages.
Test your understanding!
Let . Describe in simple English the languages corresponding to the following regular expressions:
a(a ∪ b)*b(a*b)*b*(a ∪ ε)b*
Show answer
-
a(a ∪ b)*b: This describes the set of all strings over that start withaand end withb. The(a ∪ b)*part in the middle can be any string ofa's andb's, including the empty string. -
(a*b)*: This expression describes strings made up of zero or more concatenated units, where each unit consists of any number ofa's followed by a singleb. This is equivalent to the set of all strings that do not end witha, or more formally, everyais eventually followed by ab. Another way to think about it is that it's the set of all strings that do not contain the substringaa...ab...ba.... This is a tricky one! An even simpler description: any string that doesn't have two 'b's without an 'a' in between. Wait, that's not right. The simplest correct description is probably: any string where every prefix has at least as many 'b's as 'a' sequences. Let's stick to the first one: strings formed by concatenating blocks of(zero or more a's followed by a b). E.g.,b,ab,aab,bab,abaabb,εare all in the language.a,aa,baare not. The language is all strings over{a, b}where there is noaafter the lastb. Or even simpler: everyamust be followed by absomewhere later in the string. -
b*(a ∪ ε)b*: This describes the set of all strings that contain at most onea. The(a ∪ ε)part means we can have either oneaor no character (ε). Theb*parts allow any number ofb's before or after this optionala.
Conclusion
In this lesson, we established the formal foundation of regular expressions. We moved from an informal, practical understanding to a precise, theoretical one.
Key Takeaways:
- Regular expressions are a formal syntax for describing regular languages, built upon three core operations on languages: union, concatenation, and Kleene star.
- The definition is recursive: we start with atomic expressions (, , and single alphabet symbols) and combine them using the regular operations.
- Every regular expression corresponds to a specific language .
- Operator precedence ( > > ) simplifies the notation by reducing the need for parentheses.
Preview of the Next Lesson:
Now that you can define and interpret regular expressions, the next logical step is to practice creating them. In our next lesson, we will focus on constructing regular expressions for languages with specified patterns. This will hone your ability to translate an English description of a language into its corresponding regular expression, a crucial skill for both theory and practice.