I have a config file in the following format
[COMPONENT1]
KEY1=Value
KEY2=Value
KEY3=Value
[COMPONENT2]
KEY1=Value
KEY2=Value
KEY3=Value
KEY4=Value
I am having trouble writing single line regex for re.findall(), where i can get list/tuple of "COMPONENT"(s) and its respective "KEY(n)" - "VALUE" pairs to iterate through.
so far i have tried the following regex
with open(conf,"r") as config:
match = re.findall(r,"?:\[(\w+)\](?:\s*\n*)(?:(\w+(?:\s*=\s*).+)))", config.read())
It's returning
Match 1
Group1: 'COMPONENT1'
Group2: 'KEY1=VALUE'
Match 2
Group1: 'COMPONENT2'
Group2: 'KEY1=VALUE'
I am unable to formulate a regex that can show other 'Key=Value' pair.
Any help on this is really appreciated.
Note: This config format cannot be changed.