I’m not sure why I fail:
Your regex should reuse the capture group twice.
Your regex should have two spaces separating the three numbers.
Your regex should not match “42 42 42 42”.

In the console I get ["42 42 42", "42 "], which uses the capture group twice and has 2 spaces. What am I missing?

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

Because you’re not re-using the groups like you think you are.

Let’s look at this step by step. We start with “42 42 42 42”. I’ll place all the matches in a string array for clarity.

\d+

this matches groups of digits, no spaces

we get [ '42', '42', '42', '42' ]

\s

matches digits with just one 1 space following it

and we get [ '42 ', '42 ', '42 ' ]

if we stop here, we’d have 3 matches of your group [ '42 '] // #1

this is the group that gets repeated

\1

this repeats your capture group once wherever you place it

so you’re saying: repeat [ '42 ' ] once

now we get[ '42 42 ']

we only get one match because the required repeating pattern of [ '42 42 ' ] only happens once. The rest of the string looks like this [ '42 42' ]. The last ‘42’ has no space after it.

\d+

this matches any number of digits after repeating your match

so take my match of [ '42 42 ' ] and match if there’s a group of digits following

finally we have [ '42 42 42' ] // #2

we stop matching because the remaining string is [ '42' ] which doesn’t match any requirement

The reason you’re getting confused is because you think it’s repeating the capture group twice. But the numeric reference \1 only repeats in the location where it is placed.

In the console, you’re getting the result of the match, followed by the capture group that produced this result

["42 42 42", "42 "]
Index 0 is the match, which fits what we see at #2, and index 1 is the capture group which we see in #1

So you’re returning a match, while the test expects you to not match. There’s a clue in this line as to what to match and repeat

Your regex should have two spaces separating the three numbers.

and this one

Your regex should reuse the capture group twice.

Find a way to satisfy these specs while using \1 twice.

Hope that clears it up some more. Let me know if there’s something I didn’t explain clearly.

Your regex should have two spaces separating the three numbers.
Your regex should reuse the capture group twice.

suggest to me (\d+)\s\1\s\1 or (\d+)\s\1\s\1$, both which pass all the tests except 42 42 42 42. In both of these regex’s the number is repeated three times, the capture group is reused twice, and there are two spaces.

I’m at a loss for what more options I can try. I’ve used the regexr.com website and have tried over a dozen possibilities.

You are really close. The reason it won’t pass the string ‘42 42 42 42’ is because you anchored the match to the end, so it’s capturing the last 3 groups. Regex is greedy, so it will try to match as a many times as it can.

You have to anchor both sides. This is the only way to match a very specific repetitive pattern, unless you write a super complex regex. But then it’d probably be better to just loop over the matches.

Oh! I just solved it after looking at the next question, which explained capture groups a bit more. It helped me realize I can anchor the capture groups on both sides, just like you said–and it finally passed!