Upper and Lower Number of Matches with g flag?

hi everybody :grinning:
I have a question
after a big amount of trying to solve this challenge, finally I solve it but what makes me confused is here is my regex solution /O[h]{3,6} no/ but instead this regex that seems logical to me doesn’t work for me with (Global flag) /O[h]{3,6} no/g :roll_eyes:

so what is the difference and what makes the second doesn’t work even if it seems logic? :roll_eyes: :grinning:

If the regex has the global flag set, test() will advance the lastIndex of the regex. A subsequent use of test() will start the search at the substring of str specified by lastIndex ( exec() will also advance the lastIndex property). It is worth noting that the lastIndex will not reset when testing a different string.

1 Like