-4

I've been asked on how to do a regex expression bewtween 0 and 13.6, but i really dont know.. anyone could help?

Thanks

sir_ask
  • 326
  • 1
  • 4
  • 16

2 Answers2

0
^([0-9](?:\.[0-9]+)?|1[0-2](?:\.[0-9]+)?|13(?:\.[0-5][0-9]+)?|13(?:\.60*)?)$
zolo
  • 444
  • 2
  • 6
  • 1
    i've not tested.. but it's similar to what i got working. Thanks – sir_ask Jul 30 '15 at 20:40
  • Didn't see that you got solution for this, didn't know that you have a working one already. – zolo Jul 30 '15 at 20:44
  • This has issues. It won't match `13`, `13.0`, or `13.12`. You're allowing `0-12` to have optional decimals and multiple decimal places. But for `13`, it must be: `13.1`, `13.2`, `13.3`, `13.4`, `13.5`, or `13.6` only. – Bond Jul 31 '15 at 04:01
  • corrected the regexp. but I dont understand clearly, how many digits can have after the decimal point? – zolo Jul 31 '15 at 05:57
0
(?<![\.\d])\d\b(?:\.\d+)?|(?<=1)[0-2]\b(?:\.\d+)?|(?<=13)\.?[0-2]?|(?<=13.5)(?:\.\d+)?|13\.6

this will find every instance that exists in a string, doesnt necessarily have to start and end as the number

maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37