Confused by Solution for Reuse Patterns Using Capture Groups

Tell us what’s happening:

So I’m confused as to why the solution below works for the test case “42 42 42 42”. The ^ tests whether or not the pattern is at the beginning which is true, and the $ tests whether the pattern is at the end which is again true. How does combining the two return false for the test case?

Your code so far


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

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

Your regex /^(\d+)\s\1\s\1$/; matches a string of digits that is repeated exactly three times, and no more or less. Since “42 42 42 42” repeats four times, it does not match.