Specify Upper and Lower Number of Matches can someone explain

Tell us what’s happening:

The question says : Change the regex ohRegex to match only 3 to 6 letter h 's in the word "Oh no" .
so, i thought the solution is simply

let ohRegex = /h{3,6}/;
but it won’t pass for ohStr = “Ohhhhhhh no”
can someone explain what is going on actually?

Your code so far


let ohStr = "Ohhh no";
let ohRegex = /h{3,6}/; // Change this line
let result = ohRegex.test(ohStr);

Your browser information:

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

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

So, it doesn’t want you to return a match if the string has more than 6 “h” characters. So your regex will need to look something more like /Oh{3,6} / being sure to include a space after the closing } since we know that there will be a space between “Ohhhhhh” and “no”

Check out regex101.com for help with building up your regular expressions.

1 Like

Thank you. That helps

A more clearer way to check for spaces is to use \s

2 Likes