Specify Exact Number of Matches to limit a pattern

Tell us what’s happening:
Hi campers, I already completed the problem through the asked method but I’d really like to understand why this one won’t work. Basically I think I’m trying there to test this pattern to only exist once through the string (of course not ha ha).

Your code so far

let repeatNum = "42 42 42";
let reRegex = /((\d+) \1 \1){1}/; // Change this line
let result = reRegex.test(repeatNum);
let Match = repeatNum.match(reRegex);
console.log(Match);
console.log(result);

Your browser information:

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

Challenge: Regular Expressions - Reuse Patterns Using Capture Groups

Link to the challenge:

Thx Randell, it’s clearer but I still can’t see it crystal clear though. Why does the number only pertain to the 2nd capture group ?

The first capture group is between the first set of ( and ). The second capture group (d+) which represents the number.

Crystal clear now. As I added the global parentheses after having created my first capture group and his reps, I mislead myself into thinking the global capture group was the second one.
Thanks a lot Randell !

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.