Reuse Patterns Using Capture Groups

Tell us what’s happening:
I double check my code by regex tester, it should be fine.

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_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:

In case anyone else arrives here, following link has the answer.


All good but specify start and stop string match.

let reRegex = /^(\d+)\s\1\s\1$/;

Can you explain why it won’t work without specifying the start?

It matches both occurrences of “42 42 42”, eg.:
42 42 42 42”
“42 42 42 42

1 Like

Sorry I am just responding to this. I want to believe that the explanation by @lynxlynxlynx does suffice. In summary, we want it to be able to search “the multiple” from end to end and when it exceeds thrice, it is not a match.

1 Like

but it did match all the requirements when I test it in that online regex app…

this should be a correct answer but it doesn’t match any requirements online, what’s wrong with that?

You didn’t test it with “42 42 42 42”

And in the screenshot, your test text contains also the parentheses, which is why it doesn’t match.