1

I want to match numbers between 0 and 799 ONLY,if it doesn't have a comma in them.


$660
http://stackoverflow.com/questions/6560030/what-regex-can-i-use-tovalidate-anumber-between-0-and-255

I've tried using this RegEx. --> \b(0*(?:[0-9]?[0-9]?[0-9]?|100))\b and it works very well. (If the number is between 0 and 999)

Need help with changing my regex:

  • I need it to work in JavaScript.
  • I'd like to validate the number in the first row using regex after the $ (I only need It,if It's between 0 and 799)
  • If it has a comma in it then it should be ignored( like numbers 799+)
  • I don't want it to accept numbers with comma in them,because my current regex thinks it's valid. (Or at least the 6,245 should be equal to 6245 so my regex can ignore it.)
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Enryu
  • 41
  • 1
  • 5

1 Answers1

0

To rephrase your question, numbers must not have a comma before them, or after:

(?<!,)\b[1-7]?\d?\d\b(?!,)

Try it online.

If you can't use look behinds, eg if you use JavaScript, you'll have to consume the non-comma and capture the target instead:

(^|[^,])(\b[1-7]?\d?\d\b(?!,))

The number is in group 1.

Try it online.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • It's almost what I need,but I only want to match the first line and ignore all the other rows where are numbers. http://rubular.com/r/YssSb8JxAL Your expression is not limited to the first row. (I only need the numbers after the $ and nothing else(only that row)) – Enryu Sep 17 '16 at 22:18
  • BTW I just tried using it and It says that "Lookbehind is not supported in JavaScript".(It was my fault not saying I needed it in JavaScript) – Enryu Sep 17 '16 at 22:51