I would extract all the numbers contained in a string. Which is the better suited for the purpose, regular expressions or the isdigit()
method?
Example:
I'm assuming you want floats not just integers so I'd do something like this:
l = []
for t in s.split():
try:
l.append(float(t))
except ValueError:
pass
Note that some of the other solutions posted here don't work with negative numbers:
>>> re.findall(r'\b\d+\b', 'he33llo 42 I\'m a 32 string -30')
['42', '32', '30']
>>> '-3'.isdigit()
False