RegExp Character Sets Quiz

Quiz 3 9 questions

Prerequisites for the quiz

  1. RegExp Character Sets chapter

Are you ready?

9 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
Which of the following strings will the expression /[10]+/ match?
  1. "10101010"
  2. "000"
  3. "10"
  4. "[10]"
/[10]+/ will give a positive result on all strings that contain a sequence of the characters '0' and/or '1'. For more details please refer to JavaScript RegExp Character Sets.
Are the sets [135] and [153] equal?
The order of characters inside a set doesn't matter. What matters is just the presence of given characters. For details refer to JavaScript RegExp Character Sets.
Consider the the substrings below.
  1. "AaBbcP"
  2. "aZzXyb"
  3. "lmNoPqrhg"
  4. "zWxSrfFla"

Which of the following expressions matches all of these?

All the given substrings are sequences of alphabets, both lowercase and uppercase. Choices B) and C) match both these cases, and are actually interchangeable. Thus the correct choice is D). For details refer to JavaScript RegExp Character Sets.
Are the following two expressions equivalent?
  1. /[a-d]/i
  2. /[abcdABCD]/
/[a-d]/i matches a single character from a to d, or A to D. Similarly, /[abcdABCD]/ matches a single character from a to d, or A to D. Hence both expressions are identical.
How is a character set denoted?
A character set is denoted using [] square brackets. For further details please refer to JavaScript RegExp Character Sets.
What is the problem in the expression below?

/[a-Z]/

/[a-Z]/ has an invalid range because a lowercase a is followed by an uppercase Z, which is wrong.
What will be the value of str after the following code is run?
var str = "230 = 100 + 130";
var patt = /[100-200]/g;

str = str.replace(patt, "o");
The expression /[100-200]/g; matches all the characters '0', '1' and '2'. Unlike the false perception, it doesn't match the numbers from 100 to 200.

This means that after running the code here, str will become equal to "o3o = ooo + ooo", as each matched character is replaced with an 'o'. See more at JavaScript RegExp Character Sets - Range of Characters.
Which of the following strings will the expression /bo[^x-z]/ match?
  1. "box"
  2. "bot"
  3. "bow"
  4. "boy"
The expression /bo[^x-z]/ matches all substrings except for "box", "boy" and "boz". In this case, it matches only choices 2) and 3) in the list given above. See more details on negated sets in JavaScript RegExp Negated Character Sets.
Which parts of the string "1544200-48445968-89" does the expression /[2-5-]/g match?
The set /[2-5-]/g matches any of the characters: 2, 3, 4, 5 and -. The correct choice is therefore C).