The quantity specifiers in regex. Is upper limit really a limit?

The upper and lower limits are specified in code. But I see that it also matches if a character appears more times than upper limit.
.
Like {3,6} matches all characters appearing 3 or more times consecutively. But it also matches characters appearing more that 6 times.
If that’s how it was supposed to be, then whats the meaning of setting upper limit. I don’t find any use of it.

Yes, it is a limit. But don’t use the g flag or it doesn’t obviously work
Check it yourself

Haven’t you already posted this question like 10 times?

Normally you set the start: ^ and end: $ of the string within your regex.
^b{3,6}$ will match b 3-6 times and if you go below or above it won’t match.
That’s even if you use the global-flag.

1 Like

Just 2 times…LOL. I didn’t get replied though

It will work with beginning and ending characters, but why wont it work witout them.

Freecodecamp lesson defined them as lower and upper number of characters, it is not sticking to that.
Even /g flag would be outsider…
.
I hope you understood what I wrote, 'Cause I did’t. :grinning:

Whether it matches or not will depend on where it is in your pattern. Remember that these checks are whether the string contains the pattern. If your expression is something like a{3,6} then “aaaaaaa” or “aaaaaab” will match because they do contain three to six 'a’s. If your pattern is za{3,6}z, then “zaaaaaaaaaaaaz” will not match because the pattern does not contain a ‘z’ followed by three to six 'a’s followed by a ‘z’.

1 Like