Jan-16-2021, 12:44 AM
I would usually think of regex with that description,nice way not using regex bye BashBedlam.
So something like this with a combo with compile/finditer make it faster if iterate over large amount of data.
So something like this with a combo with compile/finditer make it faster if iterate over large amount of data.
import re data = '''\ Line 1: 123 NUBA AA=1.2345 $BB=1234.55 Line 2: 123 NUBA MM AA=1.2345678&BB=1234.55 Line 3: 123 NUBA RRNJH AA=1.2#ALPHA''' pattern = re.compile(r"AA=([+-]?([0-9]*[.])?[0-9]+)") for match in pattern.finditer(data): print(float(match.group(1)))
Output:1.2345
1.2345678
1.2