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