Regular expressions, regular grammars, and regular languages are fundamental concepts in automata theory. They provide different ways to represent and describe patterns in strings.
Regular Expressions
A regular expression is a symbolic notation used to represent a regular language over an alphabet.
The basic rules for constructing regular expressions are:
- ε is a regular expression representing the language {ε}.
- Every symbol a ∈ Σ is a regular expression representing {a}.
- If R and S are regular expressions, R + S represents their union.
- If R and S are regular expressions, RS represents their concatenation.
- If R is a regular expression, R* represents zero or more repetitions of R.
Examples:
| Description | Regular Expression | Regular Language |
|---|---|---|
| Set of vowels | (a + e + i + o + u) | {a, e, i, o, u} |
| ‘a’ followed by 0 or more ‘b’ | ab* | {a, ab, abb, abbb, abbbb, ...} |
| Any number of vowels followed by any number of consonants | [aeiou]*[bcdfghjklmnpqrstvwxyz]* | {ε, a, aou, aiou, b, abcd, ...} (ε represents empty string) |
Note: Character classes such as [aeiou] are commonly used in practical regular-expression syntax. In formal regular-expression notation, they can be represented using union.
Regular Grammar
A regular grammar is a formal grammar that generates a regular language. It consists of:
- Terminals: Symbols used to form strings, such as a and b.
- Non-terminals: Variables used in production rules, such as S and A.
- Production rules: Rules used to generate strings.
- Start symbol: The non-terminal from which derivation begins.
Regular grammars are of two types:
Right-linear Grammar: Production rules have the form A → aB or A → a.
Example: S → aS | bS | ε
- This grammar generates all strings over {a, b}, represented by (a + b)*.
- Left-linear Grammar: Production rules have the form A → Ba or A → a.
Example: S → Sa | Sb | ε
This grammar also generates all strings over {a, b}.
Regular Languages
A regular language is a language that can be represented by a regular expression, generated by a regular grammar, or recognized by a finite automaton (DFA or NFA).
Properties of Regular Languages
1. Closure Properties
Regular languages remain regular under several operations:
- Union: If L₁ and L₂ are regular, L₁ ∪ L₂ is also regular. For example, if L₁ = a* and L₂ = b*, then L₁ ∪ L₂ is regular.
- Intersection: If L₁ and L₂ are regular, L₁ ∩ L₂ is also regular.
- Concatenation: If L₁ and L₂ are regular, L₁L₂ is also regular. For example, ab is regular.
- Kleene Closure: If L is regular, L* is also regular. For example, if L = {a, b}, then L* = (a + b)*.
- Complement: If L is regular over an alphabet Σ, then Σ* − L is also regular.
- Difference: If L₁ and L₂ are regular, L₁ − L₂ is also regular.
- Reversal: If L is regular, the language containing the reversals of all strings in L is also regular.
2. Finite Automata
Every regular language can be recognized by a finite automaton, such as a DFA or NFA.
3. Decision Problems
The following problems are decidable for regular languages:
- Membership: Determine whether a given string belongs to a language.
- Emptiness: Determine whether a language contains any strings.
- Equivalence: Determine whether two regular expressions or finite automata represent the same language.
Note: Two regular expressions are equivalent if they generate the same language. For example, (a + b*)* and (a + b)* are equivalent because both generate all strings over {a, b}.
Comparison of Regular Expressions, Regular Grammars, and Regular Languages
| Aspect | Regular Expressions | Regular Grammars | Regular Languages |
|---|---|---|---|
| Definition | Symbolic representation of string patterns | Formal rules for generating strings | Languages recognized by finite automata |
| Representation | Symbols and operators | Terminals, non-terminals, and production rules | Sets of strings |
| Use | Describing string patterns | Generating strings | Representing and recognizing regular patterns |
Problems on Regular Expressions and Regular Languages
Question 1: Which of the following languages over the alphabet {0, 1} is described by the regular expression (0 + 1)*0(0 + 1)0(0 + 1)?
(A) The set of all strings containing the substring 00.
(B) The set of all strings containing at most two 0s.
(C) The set of all strings containing at least two 0s.
(D) The set of all strings that begin and end with either 0 or 1.
Solution:
- Option A is incorrect because the string 10101 belongs to the language but does not contain the substring 00.
- Option B is incorrect because strings such as 00000 belong to the language and contain more than two 0s.
- Option C is correct because the expression requires at least two occurrences of 0.
- Option D is incorrect because the expression requires at least two 0s and a minimum string length of three.
Correct Answer: (C)
Question 2: Which of the following languages is generated by the given grammar?
S → aS | bS | ε
(A) {aⁿbᵐ | n, m ≥ 0}
(B) {w ∈ {a, b}* | w has an equal number of a's and b's}
(C) {aⁿ | n ≥ 0} ∪ {bⁿ | n ≥ 0} ∪ {aⁿbⁿ | n ≥ 0}
(D) {a, b}*
Solution:
The production rules allow the generation of either a or b at every step. The derivation can also stop at any point using S → ε. Therefore, the grammar generates all possible strings over {a, b}, including ε and strings such as ab, ba, aab, and bba.
Correct Answer: (D)
Question 3: The regular expression 0*(10*)* denotes the same language as:
(A) (10)1
(B) 0 + (0 + 10)
(C) (0 + 1)10(0 + 1)
(D) None of these
Solution:
The expression 0*(10*)* can generate any string over {0, 1}. It allows any number of 0s before the first 1 and any number of 0s after each 1. Therefore, it is equivalent to (0 + 1)*. None of the expressions in options A, B, or C represents (0 + 1)*.
Correct Answer: (D)
Question 4: The regular expression for the language over the input alphabet {a, b}, in which two a's do not occur consecutively, is:
(A) (b + ab)* + (b + ab)a
(B) a(b + ba) + (b + ba)*
(C) Both (A) and (B)
(D) None of the above
Solution:
The language contains all strings over {a, b} that do not have two consecutive a's.
- Option A is correct because (b + ab)* generates strings ending in b or ε, while (b + ab)*a generates strings ending in a. Together, they generate all strings without consecutive a's.
- Option B is incorrect because it does not generate all valid strings. For example, it cannot generate abab, although abab belongs to the language. Therefore, only option A is correct.
Correct Answer: (A)

