Given the following pattern:
group1: hello, group2: world
group1: hello (hello, world) world, group2: world
group1: hello world
of the style <group_name>: <group_value>[, <group_name>: <group_value>[...]]
.
In general I use the following regex to extract the values:
group1:\s(?P<group1>[^,\n]+)(:?,\sgroup2:\s(?P<group2>[^,\n]+))?\n
which works file unless a ,
exists inside the group_value
.
I know that this toyexample can be solved by something like:
group1:\s(?P<group1>.+?)(?:,\sgroup2:\s(?P<group2>.+?))?\n
However I do want to protect myself agains matching everything accidentally so I would still like to limit my match when it encounters a ,
.
Question: Is there a (general) way to match up to ,
and for that purpose ignore ,
s that are in brackets?