Regex exactly n OR m times

There is no single quantifier that means “exactly m or n times”. The way you are doing it is fine.

An alternative is:

X{m}(X{k})?

where m < n and k is the value of n-m.

Leave a Comment