Reuse Patterns Using Capture Groups--

Tell us what’s happening:
I can’t see what I miss – please help me

Your code so far


let repeatNum = "42 42 42";
let reRegex = /(\d+)\s\3(\d+)\s\3/; // Change this line
let result = reRegex.test(repeatNum);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/reuse-patterns-using-capture-groups

Try using this tool to check what your regEx is targeting. :slight_smile:

@EdMagal thank you for the link
I understand each piece of the regex but I don’t understand why it is not solving the challenge

\3 is a reference to a third matched group, but you only have two groups =)

Something like this would be closer to the answer: /(d+)\s\1\s\1/
(\d+) will match any number followed by others or not
\s matches a space
\1 matches a group equal to the first captured parenthesis (in this case “42”)
\s matches a space
\1 matches an identical group again.

To get to the answer you will need to add two more special characters, so that you won’t match “42 42 42 42”.
Though, there may be many other valid answers :slight_smile:

2 Likes

Thank you;now I understand how to use \1 in /(d+)\s\1\s\1/