RegEx possible?

Tell us what’s happening:

Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36.

Challenge: Reuse Patterns Using Capture Groups

Link to the challenge:


I apologise, but I am not quite sure what you are asking here.

can this also be a possible answer?

Your regex returns the correct values for all of the test strings, but does not meet the Your regex should have two spaces separating the three numbers. test.

yeah but when i use capture groups for the second one it must capture a space and \d

Think about what capture groups are.
(\d+) is a capture group. (\d+)(\d+) is two capture groups.
What if you wanted a space between your capture groups?

See \d+ will capture a number second capture group will capture a space and a number. so its like a number space a number space a number

Great! So how would you write that as a Regex?

that’s what i wrote i think

Your Regex works for the test strings. But how would you change it to reuse a capture group twice? That’s the one test you’re missing.

but it is right for the requirements that’s the point i was asking

It will correctly test the strings for a number repeated three times with a space between each repetition, yes.

But it is not correct for the challenge requirements, no.

thanks for clarification

1 Like

Always happy to help! :slight_smile: