I have a txt file which contains the following lines:
<KEY key="Metric" keyvalue="VALUE (Base)">523.876481542546</KEY>
<KEY key="Metric" keyvalue="VALUE (Base)">1.41186111749407E-05</KEY>
I want to extract the numbers from the above using regular expressions. The numbers may include scientific notation e.g. 1.41186111749407E-05. So far I have tried (in my python script):
count = 0
for i, line in enumerate(searchlines):
if '"VALUE (Base)">' in line:
for line in searchlines[i:i+1]:
m = re.search(r'\d+\.\d+', line)
count = count + 1
if count == 1:
m1 = m.group()
if count == 2:
m2 = m.group()
This gives an output of:
m1 = 523.876481542546
m2 = 1.41186111749407
but I want:
m2 = 1.41186111749407E-05
What is the regular expression I need to handle cases with an 'E' and a minus symbol '-' ?