I have a string that includes an arbitrary number of pairs:
A=B, C=D, E=F
This is an options string, so I know "A", "C", and "E". I can query for them if I want.
I want to find malformed pairs in the string:
A=B, C, E=F # C has no equals or value
A=, C=D, E=F # A has no value
A=B, C=D, E=F X # what is X doing there!
Of course, A, C, and E are all optional and can appear in any order.
What is the elegant way to grab all the pairs, while noticing an error condition? I am able to grab pairs now using re.findall(...), but I fail in the 3rd case above.
Here's what I have. In my exact case, the right side of the pair must be quoted but that's not important for this question.
re.findall('\s*(\w+)\s*=\s*(?P<Q>[\'\"])(\w*)(P=Q)\s*,{0,1}', a_string)
If I knew that a_string was entirely consumed, I'd be a happy guy.