Description is hard to understand. What is nth?

Tell us what’s happening:

replaceText should use parenthesized submatch string(s) (i.e. the nth parenthesized submatch string, $n, corresponds to the nth capture group)

Your code so far

let str = "one two three";
let fixRegex = /change/; // Change this line
let replaceText = ""; // Change this line
let result = str.replace(fixRegex, replaceText);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36

Challenge: Use Capture Groups to Search and Replace

Link to the challenge:

This is just to say that for example $2, refers to the 2nd capture group in the regex. You are given this example:

"Code Camp".replace(/(\w+)\s(\w+)/, '$2 $1');

Good luck. Hope this helps.

1 Like
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.