Reputation: 519
I would like to write a regex that check if the input string is a number between 2 and 6 digits but not 5. Obviously, I can do something like:
^[0-9]{2,4}$|^[0-9]{6}$
but I was hoping for more succinct notation.
This is JavaScript regex. Do you think there is a shorter answer?
Many thanks!
Upvotes: 2
Views: 117
Reputation: 67968
^(?!.{5}$)\d{2,6}$
Try this.See demo.
http://regex101.com/r/yW4aZ3/116
Upvotes: 1