I have a regex pattern defined as
var pattern = ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";
and I am trying to split some CSV like strings to get fields
Some example strings that WORK with this regex are
_input[0] = ""; // expected single blank field
_input[1] = "A,B,C"; // expected three individual fields
_input[2] = "\"A,B\",C"; // expected two fields 'A,B' and C
_input[3] = "\"ABC\"\",\"Text with,\""; // expected two fields, 'ABC"', 'Text with,'
_input[4] = "\"\",ABC\",\"next_field\""; // expected two fields, '",ABC', 'next_field'
However, this is not working
_input[5] = "\"\"\",ABC\",\"next_field\"";
I am expecting three fields
'"', 'ABC"', 'next_field'
But I am getting two fields
'"",ABC', 'next_field'
Can anybody help with this regex?
I think the strange part is that the second column doesn't have quotes at the start and end of the value, just at the end. So the first column's value is empty, and the second column is ABC"
Thanks, Rob