Reuse Patterns Using Capture Groups - RegExp

Tell us what’s happening:

This is the last RegExp problem I need to finish the section. I’ve tested this expression on three different regex sites and they all return matches for:

“42 42 42”
“100 100 100”
“10 10 10”

and do not return matches for:

“42 42 42 42”
“42 42”
“101 102 103”
“1 2 3”

It passes all tests for the FCC problem set except for:

Your regex should not match “42 42 42 42”

If I put the global flag in it also does not pass the test for:

Your regex should match “42 42 42”

I’m really not sure I understand how it can pass the test for “10 10 10” but not “42 42 42”. Also having trouble understanding how “42 42 42 42” IS matching.

Your code so far


let repeatNum = "42 42 42";
let reRegex = /(\d{2,3})\s\1\s\1/; // Change this line
let result = reRegex.test(repeatNum);

Your browser information:

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

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

/^(\d+)\s\2(\d+)\s\2$/

or in your case

/^(\d{2,3})\s\1\s\1$/

add to start ^ and $ at the end to define the pattern, basically where to start and where to end;