I am trying to parse a file that has multiple key, value lines as show below
"key1" = "value1";
"key2" = "value2";
"key3" = "value3_line1
value3_line2
value3_line3";
"key4" = "value4";
I am using below code to parse this file
def parseFile(f):
regex = re.compile(r'^"(.*)"\s+=\s+"(.*)";',re.MULTILINE)
with open(f) as string_file:
alllines = string_file.read()
matches = [m.groups() for m in regex.finditer(alllines)]
for m in matches:
print(m[0], '=>', m[1])
This code matches for lines with key1, key2 and key4 but doesn't match key3. How do i fix this to get all key values pairs including those that has multiline values?
regex = re.compile(r'^"(.*)"\s+=\s+"(.*)"?;?',re.MULTILINE)?