0

I have wrote a regex which validates any number between 0-35 (inclusive). Just wondering if this is correct?

([0-9]|[1-2][0-9]|3[0-5])

Further does anyone know a numerical range regex generator? Thanks!

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 2
    Looks fine just use anchors or word boundary on both sides. – anubhava Feb 08 '16 at 14:22
  • Could be simplified to `([1-2]?[0-9]|3[0-5])` – Thomas Ayoub Feb 08 '16 at 14:24
  • @Thomas: Do not forget anchors. Wood: See [Generate a Regular Expression to Match an Arbitrary Numeric Range (Python recipe)](http://code.activestate.com/recipes/534137-generate-a-regular-expression-to-match-an-arbitrar/). Just paste into [ideone.com](http://ideone.com) and enjoy. – Wiktor Stribiżew Feb 08 '16 at 14:24
  • See more common examples here: http://www.regular-expressions.info/numericranges.html – demiters Feb 08 '16 at 14:25

0 Answers0