This actually seems to be working, but I'm having trouble reasoning about it. I'm actually working in Tcl at the moment but since it's a RegExp question I decided this would be the best place for it. Basically, I'd appreciate anyone's input as to whether this does what I think it does, and whether it does it well.
At one point I have a string containing zero or more name=value pairs, much like the parameters to an HTML tag. Like those, the values may or may not be quoted; they're either single-quoted or double-quoted strings, or sequences of nonwhitespace characters. Strings may include difficult characters (like a double quote in a double-quoted string, or a single quote in a single quoted string, amongst other things) by preceding them with a backslash. I'm using the Tcl regexp command with the -all and -inline options to get a list of all matches and submatches in a predictable order.
\s*([^\s=]+)\s*=\s*(?:([^"'\s]+)|"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)')
I've been staring at it too long to feel certain that it's as good as it's going to get. Any ideas?