How does the g flag work in this case

Hello, I just did the challenge “Regular Expressions: Specify Exact Number of Matches.” I know that the answer is /Tim{4}ber/, but it fails if I put a g flag like so /Tim{4}ber/g. Why does this occur?
P.s prompt is " Change the regex timRegex to match the word "Timber" only when it has four letter m 's."
My error message is “Your regex does not match `“Timmmmber”.”
Thank You for your time,
Ken

1 Like

The g modifier is used to perform a global match (find all matches rather than stopping after the first match).so you don’t need to use this.
In this challange you just need to match timmmmber and regex /Tim{4}ber/ will matches the word timmmmber.

if it is being tested using test method then the g flag will make so that every time the regex matches then it is changed the index at which to start the search of a match

see in the examples about use of g flag: