Regular Expressions are strings over an alphabet Σ that can be obtained as follows:
∅ is a regular expression
ϵ is a regular expression
Every element a∈Σ is a regular expression
If α,β are regular expressions, then so is αβ
If α,β are regular expressions, then so is α∪β
If α are regular expressions, then so is α∗
α are regular expressions, then so is α+
If α are regular expressions, then so is (α)
Example:
If Σ={a,b}, the following are regular expressions:
∅
ϵ
a
(a∪b)∗
abba∪ϵ
Regular Expressions Define Languages
Semantic interpretation: the language L(α) expressed by a regular expression α:
L(∅)=∅
L(ϵ)={ϵ}
L(c)={c},wherec∈Σ
L(αβ)=L(α)L(β)
L(α∪β)=L(α)∪L(β)
L(α∗)=L(α)∗
L(α+)
If L(a) is equal to ∅, then L(a+) is also equal to ∅. Otherwise L(a+) is the language that is formed by concatenating together one or more strings drawn from L(a)
L((α))=L(α)
This is the way we create the set representations (the Regular Language) of the Regular Expression.
Sometimes it ISN'T possible to make a Regular Expression to represent a Language:
Structural Induction
Finite State Machines and Regular Expressions define the same class of languages. This means that the class of languages that can be defined with regular expressions is EXACTLY the class of regular languages.
So by something called Thompson's Construction we can build and NDFSM.
Every NDFSM that we can build using Thompson's Construction has a starting state with no incoming edges and ONEaccepting state that has no outgoing edges
Building Blocks
Here are the Building Blocks that we can use to build the NDFSM
Basic : L(∅)andL(a)wherea∈Σ
Concatenation: α=βγ→NDFSM forL(α)
Union (Or): α=β∪γ→NDFSM forL(α)
Kleene * (Star): α=β∗→NDFSM forL(α)
Example of Regular Expression to NDFSM using Thompson's Construction:
FSM To Regular Expression
Basically, take any state, and remove it from the FSM. Then you update the transition function/relation from the state on the left to the state on the right so that it is a regular expression
Example:
Formal Steps:
Create a new initial state and a new, unique accepting state, neither of which is part of a loop.
Before
After
Remove states and arcs and replace with arcs labelled with larger and larger regular expressions.
Remove State 3
Before
After
Explanation:
Remove State 2
Before
After
Explanation:
Remove State 1
Before
After
Some Extra/Real World Regular Expressions
Syntax
Name
Description
abc
Concatenation
Matches a, then b, then c where a, b, and c are any regexs
a∥b∥c
Union (Or)
Matches a or b or c where a, b, and c are any regexs
a⋆
Kleene Star
Matches 0 or more a′s where a is any regex
Finish this later
Simplifying Regular Expressions
Regex's describe sets:
Union is commutative: α∪β=β∪α
Union is associative: (α∪β)∪γ=α∪(β∪γ)
∅ is the identity for Union: α∪∅=∅∪α=α
Union is idempotent: α∪α=α
Concatenation:
Concatenation is associative: (αβ)γ=α(βγ)
ϵ is the identity for Concatenation: αϵ=ϵα=α
∅ is the zero for concatenation: α∅=∅α=∅
Concatenation distributes over Union:
(α∪β)γ=(αγ)∪(βγ)
γ(α∪β)=(γα)∪(γβ)
Kleene Star:
∅⋆=ϵ
ϵ⋆=ϵ
(α⋆)⋆=α⋆
α⋆α⋆=α⋆
(α∪β)⋆=(α⋆β⋆)⋆
Pattern Matching
Any file that contains the pattern
L(Σ⋆abcabbΣ⋆) -> NFA -> DFA -> Minimize -> gets the minimal DFSM on 43
Pattern Searching
Any file that ends with the pattern
L(Σ⋆abcabb) -> NFA -> DFA -> Minimize -> gets the minimal DFSM on 44