fork download
  1. import re
  2. pat = re.compile(r'(?:Wohnfläche|Wohnfl|Wfl)\s*(\d{1,3}(?:[.,]\d{1,2})?)\s?m\s?(qm|m\u00B2)|(\d{1,3}(?:[.,]\d{1,2})?)\s?m\s?(qm|m\u00B2)\s*(?:Wohnfläche|Wohnfl|Wfl)')
  3. strs = ["12,56m qm Wohnfläche", "14.54 mqm Wohnfl", "Wfl 134 m qm"]
  4. for x in strs:
  5. m = pat.search(x)
  6. if m:
  7. if m.group(1): # First alternative found a match
  8. print("{}".format(m.group(1), " - ", m.group(2)))
  9. else: # Second alternative "won"
  10. print("{}".format(m.group(3), " - ", m.group(4)))
  11.  
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
12,56
14.54
134