fork download
  1. import re
  2.  
  3. regex = r"\S+(?= \(KM\))"
  4. strings = ["261.30 (NM) / 300.76 (MI) / 483.93 (KM)", "952.27 (NM) / 1,096.09 (MI) / 1,763.61 (KM)"]
  5.  
  6. for s in strings:
  7. matches = re.search(regex, s)
  8. if matches:
  9. print(float(matches.group().replace(',', '')))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
483.93
1763.61