Lecture 7 & 8 - Regular Expressions
Lecture 7 & 8 - Regular Expressions
Hence (S+)+ = S+
Introduction – Regular Expression
Previously, we used phrases to describe a language
E.g. L = { xn for n = 1, 2, 3, …}
– This means, language L contains all combination of x of
any length except Λ
E.g. L = { xn for n = 1, 3, 5, …}
– This means, language L will have all strings of odd length
* will produce Λ
Regular Expression
What language is defined by the following
expression ab*a
– L = {aa, aba, abba, abbba}
– Description?
– x(xx)* or (xx)*x
– x*xx* ?
Regular Expression - Plus Operator
Let Expression (E) = x + y
E.g. Σ = {a, b, c}
– R.E = (a + c) b*
Regular Expression – Examples
L = { aaa, aab, aba, abb, baa, bab, bba, bbb }
– R.E = (a + b) (a + b) (a + b)
– R.E = (a + b)*
– (a + b)5 ?
Regular Expression – Examples
L = All words that start with ‘a’ over Σ = {a, b}
–R.E = a (a + b)*
L = All words start with ‘a’ and ends with ‘b’ over Σ
= {a, b}
–R.E = a (a + b)* b
– If r1 = aa + b (aa + b)*
Regular Expression – Union of Two Languages
Let R.E (a + b)* a (a + b)*
– b*ab*a(a + b)*
– b*ab*ab*
Regular Expression – Examples
(a+b)* a (a+b)* b (a+b)* + (a+b)* b (a+b)* a (a+b)* = (a+b)* a (a+b)* b (a+b)* + bb*aa*
Regular Expression – Examples
– Words that do not contain both ‘a’ and ‘b’ are the words óf
all a’s, b’s or Λ
In algebra ab = ba
In formal languages ab ≠ ba
In algebra ab = ba
In formal languages ab ≠ ba