diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.english.md
index ca4e5c88dc..084ebde896 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.english.md
@@ -28,7 +28,7 @@ You can also access capture groups in the replacement string with dollar signs (
## Instructions
"good"
. Then update the replaceText
variable to replace "good"
with "okey-dokey"
.
+Write a regex fixRegex
using three capture groups that will search for each word in the string "one two three". Then update the replaceText
variable to replace "one two three" with the string "three two one" and assign the result to the result
variable. Make sure you are utilizing capture groups in the replacement string using the dollar sign ($
) syntax.
"good"
. Then up
tests:
- text: You should use .replace()
to search and replace.
testString: assert(code.match(/\.replace\(.*\)/));
- - text: Your regex should change "This sandwich is good."
to "This sandwich is okey-dokey."
- testString: assert(result == "This sandwich is okey-dokey." && replaceText === "okey-dokey");
+ - text: Your regex should change "one two three"
to "three two one"
+ testString: assert(result === "three two one");
- text: You should not change the last line.
- testString: assert(code.match(/result\s*=\s*huhText\.replace\(.*?\)/));
+ testString: assert(code.match(/result\s*=\s*str\.replace\(.*?\)/));
+ - text: fixRegex
should use at least three capture groups.
+ testString: assert((new RegExp(fixRegex.source + '|')).exec('').length - 1 >= 3);
+ - text: replaceText
should use parenthesized submatch string(s) (i.e. the nth parenthesized submatch string, $n, corresponds to the nth capture group).
+ testString: '{
+ const re = /(\$\d{1,2})+(?:[\D]|\b)/g;
+ assert(replaceText.match(re).length >= 3);
+ }'
```
@@ -53,10 +60,10 @@ tests: