0

I have a product feed with products that have prices ranging from 0 - 10000.

The product price is populated for each product.

I want to match products that have prices over 1500 using RegEx.

I have searched online to find out how to match numeric ranges, but I am struggling to figure out how to do it.

Can you tell me what RegEx should I use to match numeric values above 1500.

Thanks so much.

PS - due to the limitations with the system I am using, we can only use RegEx to try achieve the above.

  • Which Regex engine are you targeting? And please add examples of data that should be and should not be matched. – Richard Jul 11 '16 at 10:18

1 Answers1

0

This

1[5-9]\d{2,}|[2-9]\d{3,}|1\d{4,}

will match the number 1500 and above. Check it out here at regex101.

But regex isn't really made to do mathematical tasks. You sure there isn't another way?

SamWhan
  • 8,296
  • 1
  • 18
  • 45
  • What if a phone number is accidentally within inputs? – revo Jul 11 '16 at 10:32
  • I do not think this is a math task, a regex can match specific amounts of specific characters. – Wiktor Stribiżew Jul 11 '16 at 10:40
  • @revo Tough luck I'd say ;) But OP could take a look at [this answer](http://stackoverflow.com/questions/37567406/get-number-from-giver-string-using-regex/37571199?s=1|0.3733#37571199) in which certain currency symbols are used to identify monetary amounts. Maybe combine that regex with this answer. – SamWhan Jul 11 '16 at 11:09
  • @WiktorStribiżew Well, in my world comparing two numbers **is** a mathematical task. It's done by subtracting one from the other and examining the result. But as the answer proves, it is (to a certain extent) possible to do simple range tests using regex. – SamWhan Jul 11 '16 at 11:14
  • Your regex (as any other) does not compare anything :) It only *matches* a specific sequence of specific amounts of digits. – Wiktor Stribiżew Jul 11 '16 at 11:15
  • So by that mean I think you have a worth noting word for OP to update your answer with. – revo Jul 11 '16 at 12:23