1. Which of the following matches regexp a(ab)*a
a) abababa
b) aaba
c) aabbaa
d) aba
e) aabababa
2. Which of the following matches regexp ab+c?
a) abc
b) ac
c) abbb
d) bbc
3. Which of the following matches regexp a.[bc]+
a) abc
b) abbbbbbbb
c) azc
d) abcbcbcbc
e) ac
f) asccbbbbcbcccc
4. Which of the following matches regexp abc|xyz
a) abc
b) xyz
c) abc|xyz
5. Which of the following matches regexp [a-z]+[\.\?!]
a) battle!
b) Hot
c) green
d) swamping.
e) jump up.
f) undulate?
g) is.?
6. Which of the following matches regexp [a-z][\.\?!]\s+[A-Z]
(\s matches any space character)
a) A. B
b) c! d
c) e f
d) g. H
e) i? J
f) k L
7. Which of the following matches regexp <[^>]+>
a) <an xml tag>
b) <opentag> <closetag>
c) </closetag>
d) <>
e) <with attribute="77">
Now that you are a pro at evaluating regular expressions, answer the following questions in your write-up.
1. Write a regular expression to describe strings containing only the letters {a, b, c} that are in sorted order.
^a*b*c*$
(Assuming that the phrase "only the letters {a, b, c}" implies "only the letters {a, b, c} if any" rather than "only and each of the letters {a, b, c}")
2. Write a regular expression for each of the following sets of binary strings (ie. strings that contain only 0's and 1's).
a) contains at least three consecutive 1s
[01]*1{3,}[01]*
b) contains the substring 110
[01]*110[01]*
c) contains the substring 1101100
[01]*1101100[01]*
d) doesn't contain the substring 110
^((0*(10)*)*1*|1*)$
3. Write a regular expression that would return words whose letters are in alphabetical order, e.g., almost and beef.
^[aA]*[bB]*[cC]*[dD]*[eE]*[fF]*[gG]*[hH]*[iI]*[jJ]*[lL]*[mM]*[nN]*[oO]*[pP]*[qQ]*[rR]*[sS]*[tT]*[uU]*[vV]*[xW]*[xX]*[yY]*[zZ]*$ (Assuming that "return words" means "matches words" as the examples "almost" and "beef" suggest.)