Challenge-guide-reuse-patterns-using-capture-groups

Please suggest the need of ^ and $ in this.

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 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Reuse Patterns Using Capture Groups

Link to the challenge:

Hello there,

That is what HINT 3 was trying to hint for users to do:

Hint 3
The code below:

let testString = "test test test test test test";
let reRegex = /(test)(\s)\1\2\1/g;
let result = reRegex.test(testString);

because we used \g , our Regex doesn’t return after first full match ( test test test ) and matched all repetitions. Think about how you can assert the start and end of the string.

But, I did add the last line, as more of a hint.

the g flag doesn’t do that with test method tho, seems a thing from the match method

it advances the index to which start testing
there should not be suggestion to use g flag here