Reputation: 13
I'm setting up some rules on an email filtering appliance and it will only accept regular expressions to define numeric ranges. Unfortunately I know absolutely nothing about regular expressions. I need to flag values between a certain range. for example I need to start at value 1000001 and end at value 8000000 I have partially done this with this command Kudos to this gentleman
(?<!\d)(?!1000000)\d{7}(?!\d)
This works great, except it flags 7 digit values 1000001 and above. How can I set a limit on this? Or would I need to write a completely new expression?
Upvotes: 0
Views: 1846
Reputation: 33351
if you change \d{7}
to [1-7]\d{6}
that would ensure that the first digit found as a part of the number is within the range 1-7 (and as a bonus, eliminates the possibility of leading zeroes mucking things up).
(?<!\d)(?!1000000)[1-7]\d{6}(?!\d)
This will make the highest accepted value 7999999. If it should be inclusive of the endpoint 8000000, you could add it explicitly, something like:
(?<!\d)(?!1000000)([1-7]\d{6}|8000000)(?!\d)
Upvotes: 2