-3

What is the regex for any number, float or int, within range of 95 to 106?

  • 95 to 106 are acceptable values
  • 95.0 and 106.0 are valid inputs along with all floats within range
  • 95 and 106.0 are also valid inputs
ericOnline
  • 1,586
  • 1
  • 19
  • 54
  • 2
    Does this answer your question? [Regular Expression: Numeric range](https://stackoverflow.com/questions/1377926/regular-expression-numeric-range) – rebusB May 07 '20 at 01:52
  • Regular Expressions aren't the right tool for this. https://stackoverflow.com/a/1377937/1247512 answers a similar question thoughtfully. – David May 07 '20 at 01:54
  • @rebusB, allowing floats as well as integers complicates things, depending on the amount of verification desired (rejecting `101.1.3`, for example). – Cary Swoveland May 07 '20 at 04:25

1 Answers1

0

Assuming that temperatures are representations of integers or floats having a digit after the decimal point, you could use the following regular expression.

Demo

The regex engine engine performs the following operations.

\b             match a word break
(?<!\.)        the following character is not preceded by '.'
(?:            begin a non-capture group
  (?:          begin a non-capture group
    9[5-9]     match '9' followed by '5', '6', '7', '8' or '9'
    |          or
    10[0-5]    match '10' followed by '0', '1', '2', '3', '4' or '5'
  )            end a non-capture group
  (?:\.\d)?    optionally match a decimal and one digit
  |            or
  106          match '106'
  (\.0)?       optionally match '.0'
)              end non-capture group
(?!\.)         the previous character is not to be followed by '.'
\b             match a word break
Cary Swoveland
  • 106,649
  • 6
  • 63
  • 100