So I have a text file that is feeding me comma separated data that is enclosed in double quotes like so:
string test = "\"foo\",\"bar\",\"1\",\"\",\"baz\"";
I want to capture every value, originally I simply split on comma, but I noticed sometimes things had commas between the quotes, so I changed it to instead use a regex to just pull everything between quotes with a very simple regex:
string pattern = "\"[^\"]*\"";
Using regexpal this returns exactly what I want, but for whatever reason or another when I run this small program in c#, I get returned a list of all commas, instead of the values I'm actually interested in, I'm not really sure why. Can anyone spot my error?
string test = "\"foo\",\"bar\",\"1\",\"\",\"baz\"";
string pattern = "\"[^\"]*\"";
string[] lines = Regex.Split(test, pattern); //Returns a list of commas in quotes