Sunteți pe pagina 1din 14

Regular Expressions

10/6/2019 1
Regular Expressions
Regular expressions
describe regular languages

Example: ( a  b  c) *

describes the language


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

10/6/2019 2
Recursive Definition – more elaboration
Primitive regular expressions: ,  , 

Given regular expressions r1 and r2

r1  r2
r1  r2
Are regular expressions
r1 *
r1  Note that dot is
for concatenation
10/6/2019 3
Examples

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

Not a regular expression: a  b  

10/6/2019 4
Languages of Regular Expressions

Lr =Language(r) : language of regular


expression r

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

10/6/2019 5
Definition

For primitive regular expressions :

L   

L    

La   a
10/6/2019 6
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 r  Lr1 
1
* *

10/6/2019 7
Example
Regular expression: a  b   a*

 
L a  b a  La  b  L a
*
  *

 La  b  L a *
 
 La   Lb  La 
*

 a b a


*

 a, b , a, aa, aaa,...


 a, aa, aaa,...,b, ba, baa,...
10/6/2019 8
Example

Regular expression r  a  b * a  bb 

Lr   a, bb, aa, abb, ba, bbb,...

10/6/2019 9
Example

Regular expression r  aa  bb  b


* *

Lr   {a b
2n 2m
b : n, m  0}

10/6/2019 10
Example

Regular expression r  (0  1) 00 (0  1)
* *

L(r ) = {all strings with at least


two consecutive 0}

10/6/2019 11
Example

Regular expression r  (1  01) (0   )


*

L(r ) = { all strings without


two consecutive 0 }

10/6/2019 12
Equivalent Regular Expressions

Definition:

Regular expressions r1 and r2

are equivalent if L(r1)  L(r2 )

10/6/2019 13
Example
L = { all strings without
two consecutive 0 }

r1  (1  01) (0   )
*

r2  (1 011 ) (0   )  1 (0   )
* * * *

r1 and r2
L(r1)  L(r2 )  L
are equivalent
Reg. expressions
10/6/2019 14

S-ar putea să vă placă și