Challenge not working or am I doing it wrong?

Tell us what’s happening:
I have so it repeats 3 times but it says it repeats 4 times?

I looked at the hint to found out if I had done something wrong but they use repeat for the space, but in the challenge they don’t mention that and it still should give the same results, because I only use 2 spaces and repeats the numbers 3 times, and I’m not using any g so it should then repeat 3 times only.

Tried the hints way of writing the code and still not working.

checked the solution at the hint and it worked, so had to use ^ and $ but, still don’t understand how it could match 4 times?
Your code so far

let repeatNum = "42 42 42";
let reRegex = /(\d{1,})\s\1\s\1/; // Change this line
let result = reRegex.test(repeatNum);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Reuse Patterns Using Capture Groups

Link to the challenge:

1 Like

test will return true if the pattern is present in the string. If you want exactly and nothing more than the pattern in the string you also have to say that the pattern has to start at the start of the string and end at the end of the string


But how could it repeat 4 times when I only wrote down to repeat 3 times?

1 Like

you wrote it to match a part of the string, if there is a part of the string where a number repeat three times, it will match

42 42 42 42

here I’m pointing to the part of the string that is matched

there is a way to impose how a string should start and how it should end that may be useful for you

1 Like

Does that mean if the challenge said " Your regex should not match 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42" It would be same as "
Your regex should not match 42 42 42 42"

Still be an X on the completion list?

1 Like

yep, at this time your regexxreturns true for both

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.