Specify Exact Number of Matches(why exactly is this code not working)

I know the answer /Tim{4}ber/

but could someone explain why something like /.m{4}ber/ is not working , why exactly does it not return 30 m’s part. They all work except with the 30m’s in it.

Your code so far


let timStr = "Timmmmber";
let timRegex = /.m{4}ber/; // Change this line
let result = timRegex.test(timStr);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/specify-exact-number-of-matches

Because the . will match anything, including another m. So it matches Timmmmmmmmber (matched 5 letters “m” and “ber”).

1 Like

Thanks man …