How do you find and match strings with regular expressions?
Objectives
Test knowledge of use of regular expressions.
Multiple Choice Quiz
This multiple choice quiz is designed to embed the regex knowledge
you learned during this module. We recommend you work through it
sometime after class (within a week or so).
Q1. What is the special character that matches
zero or more characters?
^
#
*
C
Q2. Which of the following matches any space,
tab, or newline?
\s
\b
$
A
Q3. How do you match the stringConfidentappearing at the beginning of a line?
$Confident
^Confident
#Confident
B
Q4. How do you match the wordConfidentialappearing at the beginning of a line?
^Confidential\d
^Confidential\b
^Confidential\w
B
Q5. What does the regular expression[a-z]match?
The characters a and z only
All characters between the ranges a to z and A to Z
All characters between the range a to z
C
Q6. Which of these will match the stringsrevolution,revolutionary, andrevolutionaries?
revolution[a-z]?
revolution[a-z]*
revolution[a-z]+
B
Q7. Which of these will match the stringsrevolution,Revolution, and their plural
variants only?
[rR]evolution[s]+
revolution[s]?
[rR]evolution[s]?
C
Q8. What regular expression matches the
stringsdogorcat?
dog|cat
dog,cat
dog | cat
A
Q9. What regular expression matches the whole
wordsdogorcat?
\bdog|cat\b
\bdog\b | \bcat\b
\bdog\b|\bcat\b
C
Q10. What do we put after a character to match
strings where that character appears two to four times in sequence?
{2,4}
{2-4}
[2,4]
A
Q11. The regular expression\d{4}will match what?
Any four character sequence?
Any four digit sequence?
The letterdfour times?
B
Q12. If brackets are used to define a group,
what would match the regular expression(,\s[0-9]{1,4}){4},\s[0-9]{1,3}\.[0-9]?