Exercise 2.1 - Regular Expressions
Exercise 2.1 - Regular Expressions
1 – regular expressions
a) All strings of lowercase letters that begin and end in a
a([a-z]*a)?
b) All strings of lowercase letters that either begin or end in a (or both)
a[a-z]* | [a-z]*a
c) All strings of digits that contain no leading zeroes
INF 5110
answer = dignot9* dignot2*
f) All strings of a’s and b’s that contain no three consecutive b’s
(a | ba | bba)* (e | b | bb)
22.01.2013 1
Exercise 2.1 – regular expressions
g) All strings of a’s and b’s that contain an odd number of a’s and an odd
number of b’s (or both)
b*ab*(ab*ab*)* | a*ba*(ba*ba*)*
h) All strings of a’s and b’s that contain an even number of a’s and an even
number of b’s
(aa | bb)* ( (ab | ba) (aa | bb)* (ab | ba) (aa | bb)* )*
22.01.2013 2