Specify Upper and Lower Number of Matches - Regex

Tell us what’s happening:

I have used this solution on other regex sites where i can test it and it passes. not sure how it can be wrong.

It’s matching:

  • character ‘o’
  • strings with 3-6 character ‘h’
  • followed by whitespace and the word ‘no’
    *flags are set to global and case insensitive

Here’s my solution from another regex site.

Region%20capture%201|690x417

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 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

1 Like

No reply needed. I figured it out. For whatever reason the engine doesn’t want the global (g) flag set. Once i removed that it passed. Kinda weird given it passes some of the tests with it set. If the global flag was the issue wouldn’t it pass none instead of some?

1 Like