I am doing the regex tutorial, Regular Expressions: Use Capture Groups to Search and Replace. I can’t understand what the following error means:
replaceText should use parenthesized submatch string(s) (i.e. the nth parenthesized submatch string, $n, corresponds to the nth capture group). I’ve attached the link to the problem above and my code is below. I appreciate any feedback you may have.
let str = "one two three"; let fixRegex = /^(\D+)\s(\D+)\s(\D+)/; // Change this line let replaceText = str.replace(fixRegex, '$3 $2 $1'); // Change this line let result = str.replace(fixRegex, replaceText); console.log(result);