0

Can somebody help me with this regular expression? Numbers that are anything from 100 to 9999. Excluding 112, 144 and the whole 900 - 999 range.

anagarD
  • 151
  • 2
  • 9
  • 2
    http://utilitymill.com/utility/Regex_For_Range – Bart Kiers May 09 '14 at 09:13
  • Regular expressions are a poor choice of tool for this problem. Better is to use a blend of regular expressions and code-behind. Use a regular expression to detect all-digits, then code-behind to do the range checking. – Raymond Chen May 09 '14 at 09:14

2 Answers2

4

This is a great opportunity to not use regular expressions at all. You are interested in the value of the numbers not their textual format so just convert the value into an integer ( if the conversion fails you have bad input ) and then perform a numerical analysis on it.

This will be easier, more readable and very probably perform better than using a regular expression.

glenatron
  • 11,018
  • 13
  • 64
  • 112
3

You can use this regex if regular script/language constructs don't work for you:

^(?!(9[0-9]{2}|112|144)$)[1-9][0-9]{2,3}$
anubhava
  • 761,203
  • 64
  • 569
  • 643