For something like this, re.findall works fine:
>>> import re >>> myString = "Test1 [cm]: -35.00/-34.99/-34.00/0.09" >>> re.findall(r'([+-]?\d+\.\d+)',myString) ['-35.00', '-34.99', '-34.00', '0.09']
You can get floats directly with a list:
>>> [float(f) for f in re.findall(r'([+-]?\d+\.\d+)',myString)] [-35.0, -34.99, -34.0, 0.09]
Or the second one is:
>>> re.findall(r'([+-]?\d+\.\d+)',myString)[1] '-34.99'
The question will be, how large a range of text floating points will you accept? Some without decimal points? Exhibitors?
>>> myString = "Test1 [cm]: -35.00/-34.99/-34.00/0.09/5/1.0e6/1e-6"
Oh! - it gets harder with regex.
Actually, you might be better off just using the python string commands:
>>> ''.join([s for s in myString.split() if '/' in s]).split('/') ['-35.00', '-34.99', '-34.00', '0.09', '5', '1.0e6', '1e-6']
You can get nth the same way:
>>> n=2 >>> ''.join([s for s in myString.split() if '/' in s]).split('/')[n] '-34.00'
Then all the weird cases work without a more complex regular expression:
>>> map(float,''.join([s for s in myString.split() if '/' in s]).split('/')) [-35.0, -34.99, -34.0, 0.09, 5.0, 1000000.0, 1e-06]