Can someone provide a regular expression for parsing name/value pairs from a string? The pairs are separated by commas, and the value can optionally be enclosed in quotes.
This is how I would do it if you can use Perl 5.10.
qr/ (?(?: [^=,\\] | (?&escape) )++ # Prevent null keys ) \s*+ = \s*+ (? (?"ed) | (?: [^=,\s\\] | (?&escape) )++ # Prevent null value ( use quotes for that ) ) (?(DEFINE) (? \\.) (? " (?: (?&escaped) | [^"\\] )*+ " ) ) /x
The elements would be accessed through %+.
perlretut was very helpful in creating this answer.