Hello regular expression experts,
There has never been a string manipulation problem I couldn\'t resolve with regular expressions until now, at least in an elegant m
I'll help you, but you have to promise to stop using the word "elegant". It's been working too hard lately, and deserves a rest. :P
(?m),(?=[^"]*"(?:[^"\r\n]*"[^"]*")*[^"\r\n]*$)
This matches a comma if, between the comma and the end of the record, there's an odd number of quotation marks. I'm assuming a standard CSV format, in which a record ends at the next line separator that isn't enclosed in quotes. Line separators are legal inside quoted fields, as are quotes if they're escaped with another quote.
Depending on which regex flavor you're using, you may have to use \r?$ instead of just $. In .NET, for example, only the linefeed (\n) is considered a line separator. But in Java, $ matches before the \r in \r\n, but not between the \r and the \n (unless you set UNIX_LINES mode).