Your regex should change "one two three" to "three two one" what should i change!

Tell us what’s happening:

Your code so far


let str = "one two three";
let fixRegex = /(\w+)\s(w+)\s(w+)/g; // Change this line
let replaceText = "$3 $2 $1"; // Change this line
let result = str.replace(fixRegex, replaceText);
console.log(result)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Use Capture Groups to Search and Replace

Link to the challenge:

Hi rohitjaiswar,
you basically solved it, but there is a little syntax error. Hint: Why is the first group different from the last two?

let fixRegex = /(\w+)\s(w+)\s(w+)/g; // Change this line
1 Like