-1

I have written a regex to exclude particular numbers 00, 000, and 255

I'm using regex - ^((?!255|00|000)[1-9]*)$

The problem I'm facing is when i enter 80 or any other number ending with 0 it excludes that number also which i don't want

mrid
  • 5,408
  • 5
  • 19
  • 56
Harmeet Kaur
  • 135
  • 11
  • Using regexes for number ranges is much like using sledgehammer to nail tiny nails. It may work, but you will get hurt. It's better to use right tool for the job - extract numbers and filter them out in your script or program. – mvp Feb 21 '19 at 05:38

1 Answers1

3

Try this version:

^(?!(?:255|00|000)$)[0-9]*$

Demo

The major change I made was to allow any digits after the negative lookahead assertion. This should be OK, because at that point you have already asserted that your blacklist numbers 00, 000, and 255 do not appear.

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263