I must suck at coding because I’m making a lot of these, soz…
anyway
let repeatNum = "42 42 42";
let reRegex = /(\d+) \1 \1/; // Change this line
let result = repeatNum.match(reRegex);
Why does this not work? Apparently it doesnt specify the amount of times I’m looking for the number to be repeated, but I thought it would because there are overall 3 references to \d+ (42), and so how could it be confused for four? There is /d at the start, and then 2 \1s after it, which overall makes three not four. I’m confused
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63
Challenge: Regular Expressions - Reuse Patterns Using Capture Groups
You have to add anchors for the start ^, and end $ of the string.
You have captured the group and made the back reference to group #1, but you haven’t created constraints for the string. This way “42 42 42” will pass equally as “42 42 42 42 42” (the first three groups will be recognized upon the regex pattern). This is not required by the instruction.
The instruction is:
"Use capture groups in reRegex to match a STRING that consists of only the same number repeated exactly three times separated by single spaces.