fork download
  1. import re
  2.  
  3. pattern = re.compile(r"\A(?P<symbol>[<>]=?)(?P<value>\d+(?:\.\d+)*)(?P<unit>%|mg/dl|cm2)\Z")
  4. s = ">=40.55%"
  5. m = pattern.match(s)
  6. if m:
  7. print(m.groupdict())
  8.  
Success #stdin #stdout 0.03s 9604KB
stdin
Standard input is empty
stdout
{'symbol': '>=', 'value': '40.55', 'unit': '%'}