0% found this document useful (0 votes)
14 views33 pages

2.0+regular Expression Part 1 MKN

Regular expressions are sequences of patterns that define strings and describe regular languages, which can be recognized by finite automata. They are used for matching character combinations in strings and can be constructed using operations like union, concatenation, and Kleene star. The document provides examples of regular expressions and their corresponding languages, as well as properties and identities related to regular expressions.

Uploaded by

sultana.sara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views33 pages

2.0+regular Expression Part 1 MKN

Regular expressions are sequences of patterns that define strings and describe regular languages, which can be recognized by finite automata. They are used for matching character combinations in strings and can be constructed using operations like union, concatenation, and Kleene star. The document provides examples of regular expressions and their corresponding languages, as well as properties and identities related to regular expressions.

Uploaded by

sultana.sara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Regular Expressions

1
Regular Expressions
Regular Expression
 The language accepted by finite automata can be easily
described by simple expressions called Regular
Expressions. It is the most effective way to represent any
language.
 The languages accepted by some regular expression are
referred to as Regular languages.

2
Regular Expressions
Regular Expression
 A regular expression can also be described as
a sequence of pattern that defines a string.

 Regular expressions are used to match


character combinations in strings. String
searching algorithm used this pattern to find
the operations on a string.

3
Regular Expressions
Example:
In a regular expression, x* means zero or more
occurrence of x.

It can generate {ε, x, xx, xxx, xxxx, .....}

In a regular expression, x+ means one or more


occurrence of x.

It can generate {x, xx, xxx, xxxx, .....}

4
Some Regular Expressions
Regular Expressions Regular Set
(0 + 10*) L = { 0, 1, 10, 100, 1000, 10000, … }
(0*10*) L = {1, 01, 10, 010, 0010, …}
(0 + ε)(1 + ε) L = {ε, 0, 1, 01}
Set of strings of a’s and b’s of any length including the null
(a+b)*
string. So L = { ε, a, b, aa , ab , bb , ba, aaa…….}
Set of strings of a’s and b’s ending with the string abb.
(a+b)*abb
So L = {abb, aabb, babb, aaabb, ababb, …………..}
Set consisting of even number of 1’s including empty string,
(11)*
So L= {ε, 11, 1111, 111111, ……….}
Set of strings consisting of even number of a’s followed by odd
(aa)*(bb)*b number of b’s,
So L = {b, aab, aabbb, aabbbbb, aaaab, aaaabbb, …………..}
String of a’s and b’s of even length can be obtained by
(aa + ab + ba + bb)* concatenating any combination of the strings aa, ab, ba and bb
including null, so L = {aa, ab, ba, bb, aaab, aaba, …………..}

5
Regular Language
Examples of Regular Expression
Example 1:
Write the regular expression for the language accepting all the
string which are starting with 1 and ending with 0, over
∑ = {0, 1}.
In a regular expression, the first symbol should be 1, and the
last symbol should be 0. The r.e. is as follows:
R = 1 (0+1)* 0
Example 2:
Write the regular expression for the language starting and
ending with a and having any having any combination of
b's in between.
The regular expression will be:
R = a b* a

6
Regular Language
Example 3:
Write the regular expression for the language starting with
a but not having consecutive b's.
The regular expression has to be built for the language:
L = {a, aba, aab, aba, aaa, abab, .....}
The regular expression for the above language is:
R = {a + ab}*
Example 4:
Write the regular expression for the language accepting all
the string in which any number of a's is followed by
any number of b's is followed by any number of c's.
As we know, any number of a's means a* any number of b's
means b*, any number of c's means c*. Since as given in
problem statement, b's appear after a's and c's appear
after b's. So the regular expression could be:
R = a* b* c*

7
Regular Language
Example 5:
Write the regular expression for the language over ∑ =
{0} having even length of the string.
The regular expression has to be built for the language:
L = {ε, 00, 0000, 000000, ......}
The regular expression for the above language is:
R = (00)*
Example 6:
Write the regular expression for the language having a
string which should have atleast one 0 and alteast
one 1.
The regular expression will be:
R = [(0 + 1)* 0 (0 + 1)* 1 (0 + 1)*] + [(0 + 1)* 1 (0 + 1)* 0
(0 + 1)*]

8
Regular Language
Example 7:
Describe the language denoted by following regular
expression
r.e. = (b* (aaa)* b*)*
The language can be predicted from the regular expression by
finding the meaning of it. We will first split the regular
expression as:
r.e. = (any combination of b's) (aaa)* (any combination of b's)
L = {The language consists of the string in which a's appear
triples, there is no restriction on the number of b's}

Example 8:
Write the regular expression for the language L over ∑ = {0,
1} such that all the string do not contain the substring
01.
The Language is as follows:
L = {ε, 0, 1, 00, 11, 10, 100, .....}
The regular expression for the above language is as follows: 9
Regular Language
Example 9:
Write the regular expression for the language containing the
string in which every 0 is immediately followed by 11.
The regular expectation will be:
R = (011 + 1)*

10
Regular Expressions
Regular expressions describe regular languages

Example: (a  b c) *
describes the language

a, bc*  , a, bc, aa, abc, bca,...

11
Recursive Definition
Primitive regular expressions: ,  , 

Given regular expressions r1 and r2

r1  r2
r1 r2
Are regular expressions
r1 *
r1 
12
Examples

A regular expression: a  b c * (c   )

Not a regular expression: a  b 

13
Languages of Regular Expressions

Lr : language of regular expression r

Example
L(a  b c) *  , a, bc, aa, abc, bca,...

14
Definition

For primitive regular expressions:

L  

L   

La  a
15
Definition (continued)

For regular expressions r1 and r2

Lr1  r2  Lr1  Lr2 

Lr1 r2  Lr1  Lr2 

Lr1 * Lr1 *

Lr1  Lr1 
16
Regular Expressions
and
Regular Languages

17
Regular Expression
Property 1. The union of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(aa)* and RE2 = (aa)* So,
L1 = {a, aaa, aaaaa,.....} (Strings of odd length excluding Null) and
L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
(Strings of all possible lengths including Null)
RE (L1 ∪ L2) = a* (which is a regular expression itself)
Hence, proved.

18
Regular Expression
Property 2. The intersection of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(a*) and RE2 = (aa)* So,
L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding Null)
RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
Hence, proved.

19
Regular Expression
Property 3. The complement of a regular set is regular.
Proof −
Let us take a regular expression −
RE = (aa)* So,
L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even length including Null)
Complement of L is all the strings that is not in L.
So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length excluding
Null)
RE (L’) = a(aa)* which is a regular expression itself.
Hence, proved.

20
Regular Expression
Property 4. The difference of two regular set is regular.
Proof −
Let us take two regular expressions −
RE1 = a (a*) and RE2 = (aa)*So,
L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε,a, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
(Strings of all odd lengths excluding Null)
RE (L1 – L2) = a (aa)* which is a regular expression.
Hence, proved.

21
Regular Expression
Property 5. The reversal of a regular set is regular.
Proof −
We have to prove LR is also regular if L is a regular set.
Let, L = {01, 10, 11, 10}
RE (L) = 01 + 10 + 11 + 10
LR = {10, 01, 11, 01}
RE (LR) = 01 + 10 + 11 + 10 which is regular
Hence, proved.

22
Regular Expression
Property 6. The closure of a regular set is regular.
Proof −
If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null)
i.e., RE (L) = a (aa)*
L* = {a, aa, aaa, aaaa , aaaaa,……………}
(Strings of all lengths excluding Null)
RE (L*) = a (a)*
Hence, proved.

23
Regular Expression
Property 7. The concatenation of two regular sets is regular.
Proof −
Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
Here,
L1 = {0, 00, 10, 000, 010, ......} (Set of strings ending in 0) and
L2 = {01, 010,011,.....} (Set of strings beginning with 01)

Then,

L1 L2 = {001,0010,0011,0001,00010,00011,1001,10010,.............}

Set of strings containing 001 as a substring which can be


represented by an RE − (0 + 1)*001(0 + 1)*
Hence, proved.
24
Identities Related to Regular Expressions

∅* = ε
ε* = ε
R R* = R* R
R*R* = R*
(R*)* = R*
RR* = R*R
(PQ)*P =P(QP)*
(a+b)* = (a*b*)* = (a*+b*)*
= (a+b*)*= a*(ba*)*
25
Identities Related to Regular Expressions

R + ∅ = ∅ + R = R (The identity for union)


R ε = ε R = R (The identity for concatenation)
∅ L = L ∅ = ∅ (The annihilator for
concatenation)
R + R = R (Idempotent law)
L (M + N) = LM + LN (Left distributive law)
(M + N) L = ML + NL (Right distributive law)
ε + RR* = ε + R*R = R*

26
Regular Expression
A Regular Expression can be recursively defined as
follows −
ε is a Regular Expression indicates the language
containing an empty string. (L (ε) = {ε})

For ε, NFA is

27
Regular Expression

φ is a Regular Expression denoting an empty


language. (L (φ) = { })

28
Regular Expression
a is a Regular Expression where L = {a}

For a NFA is

29
Regular Expression
If a is a Regular Expression denoting the language L(a)
and b is a Regular Expression denoting the language
L(b), then
 a+b is a Regular Expression corresponding to the
language L(a) ∪ L(a) where L(a+b) = L(a) ∪ L(b).

For a + b, or a | b NFA is

30
Regular Expression
If a is a Regular Expression denoting the language L(a)
and b is a Regular Expression denoting the language
L(b), then
 a.b is a Regular Expression corresponding to the
language L(a) . L(b) where L(a.b) = L(a) . L(b)

For ab, NFA is

31
Regular Expression
 R* is a Regular Expression corresponding to the
language L(R*)where L(R*) = (L(R))*

For a*, NFA is

If we apply any of the rules several times from 1 to


5, they are Regular Expressions.

32
Standard Representations
of Regular Languages
Regular Languages

DFAs

Regular
NFAs Expressions

33

You might also like