Multiple Choice Quiz

Last updated on 2023-05-03 | Edit this page

Estimated time: 60 minutes

Overview

Questions

  • 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?

    1. ^
    1. #
    1. *

C

Q2. Which of the following matches any space, tab, or newline?

    1. \s
    1. \b
    1. $

A

Q3. How do you match the string Confident appearing at the beginning of a line?

    1. $Confident
    1. ^Confident
    1. #Confident

B

Q4. How do you match the word Confidential appearing at the beginning of a line?

    1. ^Confidential\d
    1. ^Confidential\b
    1. ^Confidential\w

B

Q5. What does the regular expression [a-z] match?

    1. The characters a and z only
    1. All characters between the ranges a to z and A to Z
    1. All characters between the range a to z

C

Q6. Which of these will match the strings revolution, revolutionary, and revolutionaries?

    1. revolution[a-z]?
    1. revolution[a-z]*
    1. revolution[a-z]+

B

Q7. Which of these will match the strings revolution, Revolution, and their plural variants only?

    1. [rR]evolution[s]+
    1. revolution[s]?
    1. [rR]evolution[s]?

C

Q8. What regular expression matches the strings dog or cat?

    1. dog|cat
    1. dog,cat
    1. dog | cat

A

Q9. What regular expression matches the whole words dog or cat?

    1. \bdog|cat\b
    1. \bdog\b | \bcat\b
    1. \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?

    1. {2,4}
    1. {2-4}
    1. [2,4]

A

Q11. The regular expression \d{4} will match what?

    1. Any four character sequence?
    1. Any four digit sequence?
    1. 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]?

    1. , 135, 1155, 915, 513, 18.8
    1. , 135, 11557, 915, 513, 18.8
    1. , 135, 1155, 915, 513, 188

A

Key Points

  • Regular expressions answers