How to solve this Reuse Patterns Using Capture Groups

Tell us what’s happening:

Your code so far


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

Your browser information:

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

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

Hello!

Which test is failing ?

Your regex should not match “42 42 42 42”.

I am getting increasingly frustrated by being stuck on not passing ‘42 42 42 42’…

Honestly, I don’t know why your example doesn’t work. I tested using regex101.com and “42 42 42 42” is not matched using your regex on their app…

You can make it work with this regex : /^(\d+)\s\1\s\1$/ but it’s really not clear that we should use this.

2 Likes

Thanks Now I solved the problem.

We must use this solution because “42 42 42 42” fit the pattern at both begin and the end but what we want is to exactly fit to the pattern at both begin and the end same time.