I have a string with the structure
Resolution: 1200, Time: 16.255 (7.920 GFlop => 1487.23 MFlop/s, residual 0.007113, 500 iterations)
and I am trying to efficiently extract the floats from that string. As the stream of string does not only contain strings with this pattern but others as well. Is there a way to get the numbers from this string with the package re?
I am looking for a way like this:
import re
a = "Resolution: 1200, Time: 16.255 (7.920 GFlop => 1487.23 MFlop/s, residual 0.007113, 500 iterations)"
nbrs = re.match("Resolution: \d, Time: \d (\d GFlop => \d MFlop/s, residual \d, \d iterations)"
where \d
is an identifier for an arbitrary float? Or is the easiest way of doing this just to strip the string multiple times and check for specific contents?