Please I am stuck up

Tell us what’s happening:

Your code so far


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


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36.

Challenge: Use Capture Groups to Search and Replace

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace

the code I create therein is not going through,I’ve tried solving it but still no advancement .please am really in need of help cos I don’t wanna stuck up.

you will need to change the regex. you have not done what was asked to you.

Write a regex fixRegex using three capture groups that will search for each word in the string “one two three”.

you will need to be more specific in what you don’t understand if you want more help

Hey @Ahmadasm326
We have to save a regex in the variable fixRegex able to match the three words, you could create three different Regex as well but the challenge here is meant to show you how to use a Capture Groups approach where you create different matches groups in the Regex (\w+) to then swap the order using the replace method in the last line.

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);

Does it make sense now? It is important to understand what is behind the "$3 $2 $1" here, so let me know if it is not clear and I am more than happy to help you out in understanding this concept :slight_smile:
Happy Coding :man_technologist:

A post was merged into an existing topic: I don’t understand what is problem in this i think it’s right but isn’t running!