What is the cleanest way to obtain the numeric prefix of a string in Python?
By \"clean\" I mean simple, short, readable. I couldn\'t care less about performance, a
This is the simplest way to extract a list of numbers from a string:
>>> import re
>>> input = '123abc456def'
>>> re.findall('\d+', s)
['123','456']
If you need a list of int's then you might use the following code:
>>> map(int, re.findall('\d+', input ))
[123,456]
And now you can access the first element [0] from the above list