fork(1) download
  1. import re
  2. s = 'This is some temperature 30° c - 50 ° c 2°c 34.5 °c 30°c - 40 °c and "30° - 40, and -45.5° - -56.5° range'
  3. tb = r'-?\d+(?:\.\d+)?(?:\s*°(?:\s*c)?)?'
  4. rx = r'{0}(?:\s*-\s*{0})?'.format(tb)
  5. results = re.findall(rx, s)
  6. print(results)
Success #stdin #stdout 0.01s 27792KB
stdin
Standard input is empty
stdout
['30° c - 50 ° c', '2°c', '34.5 °c', '30°c - 40 °c', '30° - 40', '-45.5° - -56.5°']