I think I’ve found a problem on this challenge. All other tests pass except this one:
<Your regex should not match “42 42 42 42”.>
Logically my regX should work just fine and to be sure I’ve already tested it on https://regexr.com/ and all is as expected by matching only the first 3 x “42” num and their 2 in between spaces and falling short of the 3rd space and 4th “42” num.
Hope someone will see this and maybe shed some light on this problem.
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 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3350.0 Safari/537.36.
The challenge requires you to match when a string is repeated ONLY three times in a string. Your regex still passes on 42 42 42 42 because it will match the first 3 42’s as you’ve explained, however, that is not what the challenge is looking for because 42 repeated 4 times in that string.
Let’s see if I got that right, so in order to pass that test in particular, my regX should include a section that is excluding all the strings that have above 3 sub-strings that match the requirements? Then and ONLY then that test will be satisfied. If so, I’m going back at it.
Quick question on this challenge: I have a working solution that appears to be the one alluded to in this topic (defining our regex with the beginning and end of expression appended in both sides, respectively) but this would not work if the test strings were similar too “abc 12 12 12 abc”, for instance.
Is there an alternate solution that would work for that type of string? Thank you.
P.S. - I am unsure if we are meant to post the solutions or not so I will refrain from doing it