fork download
  1. import re
  2. p = re.compile(r'([-+]?[\.]?(?=\d)(?:\d*)(?:\.\d+)?)')
  3. test_str = u"WA2ąą-02 -7+12,7. PP-.5P x0.6 words"
  4.  
  5. for x in re.findall(p, test_str):
  6. print (float(x))
  7.  
  8. print(sum([float(x) for x in re.findall(p, test_str)]))
Success #stdin #stdout 0.03s 9936KB
stdin
Standard input is empty
stdout
2.0
-2.0
-7.0
12.0
7.0
-0.5
0.6
12.1