Course: JavaScript RegExp

Progress (0%)

# RegExp Quantifiers Quiz

Quiz 2 8 questions

Prerequisites for the quiz

1. RegExp Quantifiers chapter

8 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 yield a match for the expression `/39+7/`?
Which of the following strings will yield a match for the expression `/39+7/`?
1. `"397"`
2. `"3997"`
3. `"39997"`
4. `"37"`
`/39+7/` will match all substrings `'397'`, `'3997'`, `'39997'`, `'399997'` .... with one or more occurences of `'9'`. Refer to the `+` quantifier in RegExp Quantifiers for more info.
What is the range of the `?` quantifier?
The `?` quantifier has the range 0 - 1. Hence the choice A). Refer to RegExp Quantifiers for more info.
Which of the following strings will yield a match for the expression `/ant{1,2}/`?
1. `"This is an ant"`
2. `"antt"`
3. `"Wrong anttt"`
4. `"an"`
The expression `/ant{1,2}/` matches the substrings `'ant'` and `'antt'`. Since the strings 1, 2 and 3 contain this substring, they yield a match to the given expression. Hence the choice D).

The quantifiers `+` and `{1,}` are equivalent.
True or false?
Both quantifiers `+` and `{0,}` have the range 1 - Infinity, and hence are equivalent.
Which of the following quantifiers means 'zero to five occurences' ?
The custom quantifier `{0,5}` has the range 0 - 5, and hence is the right answer. The rest three choices are invalid expressions. For more info please refer to JavaScript RegExp Quantifiers.
Which of the following is the same as the quantifier `*`?
`*` has the range 0 - Infinity which is the same as that for `{0,}`. Hence the choice C). For more info please refer to JavaScript RegExp Quantifiers.
What expression will you construct to match the substring `'abbbc'`, with exactly 3 occurences of the alphabet `'b'`?

Note: The search shall be case-insensitive.

Note: You must use a quantifier.

To quantify `'b'` for exactly 3 occurences we need to use the custom quantifier `{3}`. The expression thus reduces to `/ab{3}c/i`, with the `i` flag. For more info please refer to JavaScript RegExp Quantifiers and JavaScript RegExp Flags

"I created Codeguage to save you from falling into the same learning conundrums that I fell into."

— Bilal Adnan, Founder of Codeguage