Mark Mintoff My superpower is common sense

7Mar/131

Regex Split by Comma not Surrounded by Quotes

Recently I had a requirement where I had to programmatically extract data from a very messy CSV file and populate a table. The data contained addresses, which included commas in them. In order to distinguish between a comma which separates columns and a comma in the text, the text was surrounded by double quotes.

The solution is obvious; use Regex. The regular expression however is not so straight-forward.

In C#, with escape characters:

Works like a charm.

VN:F [1.9.22_1171]
Rating: 4.9/5 (19 votes cast)
Regex Split by Comma not Surrounded by Quotes, 4.9 out of 5 based on 19 ratings
Comments (1) Trackbacks (0)
  1. Thanks for your post. I spent a lot of time searching for the syntax for this. It works like a charm!


Leave a comment

No trackbacks yet.