0% found this document useful (0 votes)
11 views

03 Regular Expression

Regular expressions describe languages by using symbols and characters to represent strings and patterns. They are made up of primitive expressions combined using operators like union, concatenation, and Kleene star. The language of a regular expression is the set of strings it describes. Equivalent regular expressions are those that describe the same language.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

03 Regular Expression

Regular expressions describe languages by using symbols and characters to represent strings and patterns. They are made up of primitive expressions combined using operators like union, concatenation, and Kleene star. The language of a regular expression is the set of strings it describes. Equivalent regular expressions are those that describe the same language.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Regular Expressions

Faryal Shamsi
Lecturer Computer Science

Sukkur IBA University


What is a Regular Expression

• An expression that describes a language

• A sequence of symbols and characters expressing a string, a pattern


or a language

2
Formal Definition of RE
Algebra for Languages
Previously we discussed these operators:

• Union
• Concatenation
• Kleene Star
Example of Regular Expression

• (a+b.c)* is a regular expression

• That describes the following language:

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


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

Not a regular expression: a  b  


Languages of Regular Expressions

• Lr  : language of regular expression r

• Example

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


• For primitive regular expressions:

L   

L    

La   a
• 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 
Example 1
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,...
Example 2

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

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


Example 3

• Regular expression r  aa * bb * b

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

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

L(r ) = { all strings with at least


two consecutive 0 }
Example 5

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

L(r ) = { all strings without


two consecutive 0 }
RE Examples
• L(001) = {001}
• L(0+10*) = { 0, 1, 10, 100, 1000, 10000, … }
• L(0*10*) = {1, 01, 10, 010, 0010, …} i.e. {w | w has exactly a single 1}
• L()* = {w | w is a string of even length}
• L((0(0+1))*) = { ε, 00, 01, 0000, 0001, 0100, 0101, …}
• L((0+ε)(1+ ε)) = {ε, 0, 1, 01}
• L(1Ø) = Ø ; concatenating the empty set to any set yields the empty set.
• Rε = R
• R+Ø = R

• Note that R+ε may or may not equal R (we are adding ε to the language)
• Note that RØ will only equal R if R itself is the empty set.
Equivalent Regular Expressions

• Regular expressions r1 and r2

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


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
regular expr.

You might also like