Regular Expressions   «Prev  Next»

Perl Regular Expression - Quiz

Each question is worth one point. Select the best answer or answers for each question.
 
1. Which metacharacter matches the end of a string?
Please select the best answer.
  A. $
  B. ^
  C. |


2. What does this expression match?
/^[abcd]/
Please select the best answer.
  A. Any string with an a, b, c, or d in it
  B. Any string that begins with a, b, c, or d
  C. Any string that begins with a lowercase a, b, c, or d

3. What does this expression do?
s/\b(\w+)\s+(\1)\b/$1/ig;
Please select the best answer.
  A. Doubles every word (for example, now now is is the the) in a line
  B. Removes doubled words (for example, now is the the time for...) from a line
  C. Removes all the w's from a line

Regular Expressions
4. What does this line do?
while(<>) { 
  /^(from|subject):/i and print 
}

Please select the best answer.
  A. Removes the headers from your email and prints out the body
  B. Removes the headers from your email and prints a blank line
  C. Prints out all the From: and Subject: lines from a mailbox

5. What does this loop do?
while(<>) {
  s/^(Subject:)\s*(.*)$/$1 Re: $2/i unless /re:/i;
  print;
}

Please select the best answer.
  A. Adds Re: to an email subject, if it's not already there
  B. Removes the subject from email
  C. Makes the Re: into lowercase


6. Which one of the following regular expressions would match the word in and the word inch, but not the word grin?
Please select the best answer.
  A. /\bin\b/
  B. /\bin/
  C. in\b/


7. What does this loop do:
while(<>) {
  s/^(.*Foo.*)$/print($1)/ie;
}

Please select the best answer.
  A. Deletes all the lines with Foo in them
  B. Prints all the lines with Foo in them
  C. Deletes all the lines without Foo in them

8. Which of the following regular expressions will match this string:
AaZzXzY
Please select the best answer.
  A. /x/
  B. /^[a-z]*$/
  C. /^\w*$/


Your score is 0.0
A
C
B
C
A
B
B
C