>>> s = r'a=foo, b=bar, c="foo, bar", d=false, e="false", f="foo\", bar"'
>>> re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', s)
['a=foo', 'b=bar', 'c="foo, bar"', 'd=false', 'e="false"', 'f="foo\\", bar"']
- The regex pattern
"[^"]*"
matches a simple quoted string.
"(?:\\.|[^"])*"
matches a quoted string and skips over escaped quotes because \\.
consumes two characters: a backslash and any character.
[^\s,"]
matches a non-delimiter.
- Combining patterns 2 and 3 inside
(?: | )+
matches a sequence of non-delimiters and quoted strings, which is the desired result.