Hi, for a strange reason, this code is not working. I tried switching to strings and even the order.
The output says:
" // running tests Your regex should change the string
one two three
to the string
three two one
// tests completed
Any ideas what could be wrong? I tried looking for other solutions but still trapped in it. Can’t skip this exercise though
Your code so far
let str = "one two three";
let fixRegex = /(\w+)\s(\w)+\s(\w+)/; // Change this line
let replaceText = "$3 $2 $1"; // Change this line
let result = str.replace(fixRegex, replaceText);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: Regular Expressions - Use Capture Groups to Search and Replace
Andrey you were right. My mistake was using “+” outside the “( )”. That little detail I foolish missed. Can’t believe I haven’t realized it, but I guess this happens a lot.
Thank you!!
Good to know you figured it out! But try not to post working solutions if you don’t have additional questions about it. It can be unwanted spoiler for other people. Thanks.