Regex greater than $75

I need a regex that approves values of $75 or greater and rejects anything lower than $75. Here is what I have at this point, which only approves $75, but nothing above. [7-9][5-9]|([1-9][0-9]+)

Upvotes: 1

Views: 432

Answers (2)

CBudtz
CBudtz

Reputation: 113

Well - going all in... This matches (and removes) the $ and takes any numbers over 75.0

\b(?<=\$)(7[5-9]|[8-9][0-9]|[1-9][0-9]{2,})\.?\d*$

(note that positive lookbehind is not supported in all languages)

But, again a little overkill - its a lot easier to strip the $, convert to double and check if the result is >= 75.0

Upvotes: 1

Ian Robertson
Ian Robertson

Reputation: 1348

While the best answer is likely "don't use regular expressions", it's possible that this might need to be done as part of a larger regular expression, where the larger use makes sense. In that case (and only that case):

7[5-9]|[8-9][0-9]|[1-9][0-9][0-9]+(\.[0-9][0-9])?

i.e one of:

  • 75-79
  • 80-99
  • anything greater than 100

Possibly followed by a decimal and two digits. (Thanks to Mike Elofson for pointing out the decimals)

Upvotes: 7

Related Questions