How can I extract lines of code that start with Value=" and end with the first occurrence of " from a text file? Script below helps me get the 'Micr' and 'Ocr' lines I need, but I don't know how to extract the value fields from them, then put them in a paired list.
file.txt
My name is Chris
<Micr Side="FRONT" Value="49116949119"/>
<Ocr Side="FRONT" Value="1238796634" Name="OCR 1"/>
My favorite food is chicken
some random text here because there is a lot more.
My name is Ben
<Micr Side="FRONT" Value="949491"/>
<Ocr Side="FRONT" Value="19919616161" Name="OCR 1"/>
My favorite food is burgers
output:
[[49116949119, 1238796634], [949491,19919616161]]
script
def read_oxi_file(self, oxi_filepath):
import re
keywords = ['<Micr', 'Name="OCR 1"']
exclude = ['Value="27','Value="/']
for fp in oxi_filepath:
with open(fp, 'r') as dat_file:
data = dat_file.readlines()
file_details.read_oxi_file(oxi_filepath)