fork download
  1. import re
  2. rx = r'\b([A-Za-z]+)\b.*?\s(\d+(?:\.\d+)?)(?!\S)'
  3. texts = ["Fluid 13.4","Fluid 13.4 gm% fluid_haemo 12.0-14.0","Fluid gm% 13.4 fluid_haemo 12.0-14.0","Fluid gm% fluid_hameo 12.0-14.0 13.4"]
  4. for text in texts:
  5. match = re.search(rx, text)
  6. if match:
  7. print(text, '=>', f'{match.group(1)} {match.group(2)}')
Success #stdin #stdout 0.02s 9584KB
stdin
Standard input is empty
stdout
Fluid 13.4 => Fluid 13.4
Fluid 13.4 gm% fluid_haemo 12.0-14.0 => Fluid 13.4
Fluid gm% 13.4 fluid_haemo 12.0-14.0 => Fluid 13.4
Fluid gm% fluid_hameo 12.0-14.0 13.4 => Fluid 13.4