Tell us what’s happening:
My mind is blowing. How do I limit BOTH number of digits in one number AND number of repeats? (Match Only 3 numbers with at least 2 digits in it => 42 42 42 or 100 100 100 but never 42 42 42 42);
Your code so far
let repeatNum = "42 42 42";
let reRegex = /(\d+)\s\1\s\1/; // Change this line
let result = repeatNum.match(reRegex);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.
@myrmidonut This challenge really threw me for a loop because in the hints section of this challenge it mentions using the global “/g” to indicate that a regex will keep looking for a match I assumed that withholding the /g meant that it would stop looking once it found a exact match for the regex I wrote.
Does hint 3 make sense to you? or would using the /g only apply when using a “.match” instead of a “.test”?
Here is my attempt at explaining this. Your code will match “42 42 42 42” because it meets the criteria you included in your RegEx. It will see that the second, third, and fourth part of the string matches your RegEx: “42 424242”
(/d+) --> will be the second 42,
(\s) --> will be the space after the second 42
\1 --> will be the third 42
\2 --> will be the space after the third 42
\1 --> will match the fourth (last) 42
Hence, your code fails because it matches the input with 4 numbers. Your code will give the same result if you provided it a string with “100 100 100 100”.
A hint, remember you can use ^ to state what we want at the beginning of a match, and $ to state what we want at the end. With that in hand, then you just focus on what should be in between.
Best of luck. And I hope this was helpful and makes sense.
So, by including a ^ at the beginning, and a $ at the end, we are basically telling it the string needs to be literally this with no extra stuff? It’s a little weird, because if I’m saying “I need 42 at the beginning, and 42 at the end” it does follow that requirement still. It’s just that it takes this literally in the middle as well? Basically…“Ok I started with 42, then space, then 42, then space, then 42…but I’m not at the end! So this isn’t right!”