I am struggling with python named group re
I have the following string: "blah blah id=xyz, blah blah foo bar=zxy] blah baz=a}"
terminating chars are: ,]}
and I would like to get out named dict using regex pattern that looks like this:
{'id': 'xyz', 'foo bar': 'zxy', 'baz': 'a'} groups should be optional
I was able to hit it without named groups and including termination characters but I am sure there is a way how to do it fully in regexp and be more elegant ... it just eludes me any help would be welcome
my current solution is using folowing pregmatch:
(id=.* ?[, }\]] |baz=.* ?[, }\]] |foo bar=.* ?[, }\]])
it works but requires significant postprocessing (string splitting and striping)
for i in ae2:
key, value = i.split('=', 1)
altevent2[key] = value.strip('},] ')
Also, it would be cool to get rid of whitespace/unprintable chars but only when they are at the start/end of the value
if at all possible it should require no postprocessing - I need a lot of performance
Edit1: list if dict 'IDs' is known in advance, for this case it would be 'id','foo bar','baz'