regex - Matching floating point range using regular expression -


i need regular expression, matches within range of floats.

for range 12.33 - 13.41 tried following regex:

(12.[3-9][3-9]|13.?[0-4][0-1]?)\d{0,2}

but doesn't match i.e. 12.41 or 13.39.

is possible regular expressions?

kind regards, bernie70

i don't know worth it, possible. try with:

(12.(3[3-9]|[4-9]\d))|(13(.([0-3]\d|4[01]))?) 

it means:

  • 12. -- starts '12.',
  • 3[3-9] -- 3 followed digit range 3 9 (33-39),
  • | -- or
  • [4-9]\d -- digit range 4 9 followed digit (40-99),
  • | -- or
  • 13 -- starts '13'
  • . -- dot
  • [0-3]\d -- digit range 0 3 followed digit,
  • | -- or
  • 4[01] -- 4 followed 0 or 1,
  • ? -- 0 or 1 time

and (.([0-3]\d|4[01]))? treated 1 group, allow '13', not '13.'

it match numbers like: 12.33, 12.99, 13.41 ,13 ,12.41 ,13.39 ,etc. , ignore: 12.32, 13.42, etc.

your code didn't work because:

(12.[3-9][3-9]|13.?[0-4][0-1]?)\d{0,2} 
  • [3-9][3-9] - allows numbers ranges (33-39,43-49,53-59,...),
  • [0-4][0-1] - allows numbers (00,01,10,11,20,21,30,31,40,41),

so there huge omitted range


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -