8.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 66edd3011f18f4ee1bd9d28b | JavaScript Regular Expressions Quiz | 8 | quiz-javascript-regular-expressions |
--description--
Answer all of the questions below correctly to pass the quiz.
--quizzes--
--quiz--
--question--
--text--
Which of the following is NOT a regular expression?
--distractors--
/hello, world!/i
new RegExp("hello, world!")
/(?:^|\s)hello[,]?\sworld[!]?(?:$|\s)/i
--answer--
"hello, world!"
--question--
--text--
Which RegExp contains the same pattern as the regular expression /f[o0]{2} b[a4@]r/i?
--distractors--
new RegExp("/f[o0]{2} b[a4@]r/", "i")
new RegExp("f[o0]{2} b[a4@]r", "g")
new RegExp("f[o0]{2} b[a4@]r")
--answer--
new RegExp("f[o0]{2} b[a4@]r", "i")
--question--
--text--
What is the return type for the regular expression method test?
--distractors--
An array of strings that matched the regular expression.
An object containing information about the (sub)string the regular expression matched.
Null, the method test only validates if the given regular expression is valid.
--answer--
A boolean indicating whether the string matches the regular expression.
--question--
--text--
What happens when match is used?
--distractors--
match searches for any strings that match the given regular expression, and returns ALL matches as an array.
match searches for the first full match, and returns the starting index of that match.
match searches for the first full match, and returns a boolean indicating whether or not a match was found.
--answer--
match searches for the first full match, and returns an array containing that first match.
--question--
--text--
Which is the best use case for test?
--distractors--
test should be used for verifying a given regular expression.
test should be used for detailed information about a string match, such as the length of the matched string.
test should be used to extract all matches from a given string.
--answer--
test should be used to check if a given string matches the regular expression.
--question--
--text--
What is the purpose of using replace?
--distractors--
replace is used to replace the current regular expression with a new regular expression.
When given an index and a string, replace replaces the character at the specified index with the string provided.
replace is a helper method for replacing an entire string with another string.
--answer--
replace replaces a matched string with a given replacement string.
--question--
--text--
What is the difference between match and matchAll?
--distractors--
match is restricted to only one match, while matchAll captures all possible matches.
match returns a boolean indicating whether a match is found, while matchAll returns a number representing the amount of matches found.
match returns a number indicating the starting index of the first match found, while matchAll returns an array of numbers containing indices where a match was found.
--answer--
match returns an array of strings that match, while matchAll returns an iterator object of all matches found.
--question--
--text--
Which of the following is the correct use of replaceAll?
--distractors--
foo.replaceAll(/foobar/, "fizzbuzz")
foo.replaceAll(/foobar/i, "fizzbuzz")
foo.replaceAll(/foobar/gi, /fizzbuzz/)
--answer--
foo.replaceAll(/foobar/g, "fizzbuzz")
--question--
--text--
Which of the following character classes is equivalent to the regular expression /[a-zA-Z0-9_]/?
--distractors--
\d
\s
\n
--answer--
\w
--question--
--text--
Which of the following character classes is best used in a regular expression that finds phone numbers?
--distractors--
\w
\s
\D
--answer--
\d
--question--
--text--
What happens when a lookahead (?=) is used in a regular expression?
--distractors--
The lookahead will assert to the left of the string, verifying that the sub-pattern IS present.
A lookahead is an alternate regular expression pattern used when the main pattern fails to match.
The lookahead will assert to the right of the string, verifying that the sub-pattern IS NOT present.
--answer--
A lookahead asserts to the right of the string, verifying that the sub-pattern IS present.
--question--
--text--
When making a regular expression, where should a lookbehind (?<=) be placed?
--distractors--
The lookbehind can be placed anywhere in the regular expression.
The lookbehind should be placed to the right of the main pattern of the regular expression.
The lookbehind should include the main pattern of the regular expression.
--answer--
The lookbehind should be placed to the left of the main pattern of the regular expression.
--question--
--text--
Which quantifier matches preceding element zero or one times?
--distractors--
+
*
a{0,}
--answer--
?
--question--
--text--
Which of the following regular expressions allows numbers between 0 and 999,999?
--distractors--
/^\d{6}$/
/^\d{0, 999999}$/
/^\d+$/
--answer--
/^\d{1,6}$/
--question--
--text--
Which of the following statements is true about the [] character class?
--distractors--
The [] character class is a set of characters to be removed from the match.
The [] character class can define a set of characters to match without the need to escape any special characters.
The [] character class represents a set of characters in Unicode form.
--answer--
The [] character class can define a custom set of characters to match.
--question--
--text--
Which of the following character classes correctly matches the uppercase alphabet?
--distractors--
\w
[a-z]
[AZ]
--answer--
[A-Z]
--question--
--text--
What happens when a capturing group (...) is used in a regular expression?
--distractors--
The capturing group is immediately evaluated, regardless of where it is located in the regular expression.
The capturing group attempts to match using the given subpattern, and continues without memorizing the result.
The capturing group is a prioritized subpattern, which will immediately return when a match is found for the subpattern.
--answer--
The capturing group attempts to match using the given subpattern, and continues with the result in memory.
--question--
--text--
What happens when a non-capturing group (?:...) is used in a regular expression?
--distractors--
The non-capturing group attempts to match using the given subpattern, and continues with the result in memory.
The non-capturing group immediately terminates when it finds a match for the given subpattern.
The non-capturing group is considered an optional match, so only a successful match is added on the result.
--answer--
The non-capturing group attempts to match using the given subpattern, and continues without memorizing the result.
--question--
--text--
What happens when a backreference (\1, \2, etc.) is used in a regular expression?
--distractors--
The backreference imports a different regular expression as a sub-pattern.
The backreference copies the sub-pattern used in a previous capturing group.
The backreference implicitly includes the match from a previous capture group to prevent the regular expression from failing.
--answer--
The backreference includes the result from a capture group as part of a pattern/sub-pattern to match.
--question--
--text--
Which part of the following regular expression causes errors?
/(?:Expense|Asset) \$\d+\.\d{2} \1 \$\d+\.\d{2}/
--distractors--
The regular expression does not make use of the whitespace character class \s.
The regular expression allows 1 or more numbers after the $.
The regular expression escapes the . and $.
--answer--
The regular expression is attempting to use a backreference to a non-capturing group.