Regular Expressions
Regular Expressions
M RATNAKAR BABU
Asst.Prof. CSE
Introduction
• The Language accepted by finite automata are easily described
by simple expressions called regular expressions.
as a regular language.
Regular Expressions
0 0
Q0
1 Q1
R U
S
Start
Start
4. If there are n accepting states, we must repeat the above steps for
each accepting states to get n different regular expressions, R1, R2,
… R n.
5. For each repeat we turn any other accepting state to non-
accepting.
6. The desired regular expression for the automaton is then the union
of each of the n regular expressions: R1 R2… RN
DFARE Example
1 1
Start 3 1 2
0
• First convert the edges to RE’s:
0 0+1
1 1
Start 3 1 2
0
DFA RE Example (2)
0 0+1
• Eliminate State 1:
1 1
Start 3 1 2
• To: 0
0+10 0+1
Note edge from 33
11
Start 3 2
Answer: (0+10)*11(0+1)*
Second Example
1 1
Start 1 2 3
• Eliminate state 2: 1
0 0+10*1
10*1
Start 1 3
Second Example (2)
0 0+10*1
10*1
Start 1 3
10*1
Start 1 3
This is just 0*; can ignore going to state 3 since we would “die”
Second Example (3)
0 0+10*1
10*1
Start 1 3
0 0+10*1
• Basis:
a
R=a
ε
R=ε
R=Ø
ε ε
T
ε
R=ST
S T
ε ε
R=S *
S
ε
RE to ε-NFA Example
a
a
b
b
a ε b
ab
RE to ε-NFA Example (2)
ab+a a ε b
ε ε
a
ε ε
(ab+a)*
a ε b
ε ε
ε ε
a
ε ε
ε
End for Now
Continue in Next Class