Regular Expressions, challenge 32 out of 33

Tell us what’s happening:

Okay, I’m stuck on this challenge. I think the problem is that I’m not representing
“fixRegex” properly. Help is greatly appreciated.

Your code so far

let str = "one two three";
let fixRegex = /(\w+)\s(\w+)\s(\w+)/; // Change this line
let replaceText = str.replace(fixRegex, '$3, $2, $1'); // 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/86.0.4240.111 Safari/537.36.

Challenge: Use Capture Groups to Search and Replace

Link to the challenge:

You actually have two problems and neither is in the regex string. The problems are here:

let replaceText = str.replace(fixRegex, '$3, $2, $1'); // Change this line

First of all, you have commas in there. The instructions say:

… update the replaceText variable to replace “one two three” with the string “three two one” …

If you notice, there are no commas in the expected output.

The second problem is that you are just supposed to create the string there, the string that will be used as the second parameter in the line below. The replace method is being applied in the line below, it doesn’t need to be applied here - this just needs to be a string.

When I fix those two problems, your code passes for me.


Wow. I missed some obvious things.

Also, since I’m here. For the last challenge, why is there a “|” operator? What is it doing there? I know what “|” generally does, but why is it here?

You would have to point me to a specific challenge - I don’t have them all memorized.

In reqex, a single pipe is a logical OR. Whereas in JS, the single pipe is a bitwise OR (the double pipe is kind of a logical OR, but is really a selector between the operands).

I think your asking what challenge it is exactly. It is Regular Expressions, challenge 33/33. Also, how would I make sure I have learned and memorized all this material?

I don’t see where the | is being mentioned. Please provide a link and a quote of the exact text in question.

And no one memorizes all this stuff - it’s too much and it keeps changing. I am constantly going to the online documentation. As you use it, more and more of it sticks. But it’s more important to learn concepts, learn what is possible, and know where to find the answer. Google is your friend.