Regular Expression
Regular Expression
A Regular Expression (or Regex) is a pattern (or filter) that describes a set of
strings that matches the pattern.
A Regular Expression can be recursively defined as follows −
• ε is a Regular Expression indicates the language containing an empty string. (L (ε) = {ε})
If we apply any of the rules several times, they are Regular Expressions.
Regular Expressions Regular Set
Some RE Examples
Any set that represents the value of the Regular Expression is called a Regular Set.
Then, L1 L2 =
{001,0010,0011,0001,00010,00011,1001,10010,.............}
All combinations of a’s means a may be single, double, triple and so on.
There may be the case that ‘a’ is appearing for zero times, which means a null string.
So L={ε,a,aa,aaa,aaaa,...}. R=a*
Design the regular expression for the language accepting all combinations of a’s except the
null string over ∑={a}.
R=a+
Design the regular expression for the language containing all the strings containing any
number of a’s and b’s.
Solution: R = (a+b)*
Construct the regular expression for the language accepting all the strings which are
ending with 00 over the set ∑={0,1}.
Solution: R = (0+1)*00
Write the regular expression for the language accepting the string which are starting
with 1 and ending with 0 over the set ∑={0,1}.
Solution: R = 1(0+1)*0
Write Regular Expression for all strings beginning with ’11 ‘ and ending with ‘ab’
11 (1+a+b)*ab
Write regular expressions for the set of a’s and b’s with at most one pair of
consecutive a’s.
(b + ab)* (aa + ɛ)(b + ab)*
Write regular expression for the language that have the set of all strings of 0’s and
1’s whose 10th symbol from the right end is 1.
(0 + 1)* 1(0 + 1)9
Write Regular Expression for the Set of all strings over {a,b}with 3 consecutive b’s.
(a/b)*bbb(a/b)*
Write Regular Expression for the Set of all strings that end with ‘1’and has no
substring ‘00’
(01+1)(01+1)*
Write Regular Expression for the language that have the set of all
strings of 0’s and 1’s such that every pair of adjacent 0’s appears
before any pair of adjacent 1’s.
R(L)=(0+10)*(1+01)*(0+ϵ).
Write Regular Expression for the language that has the set of all
strings of 0’s and 1’s not containing 101 as a substring
((0* 11*0). 0)* 1 (0/1)*
Write regular expressions for the set of strings of 0’s and 1’s whose
number of 0’s is divisible by 5.
(1*01*01*01*01*01*)*