I have to split a string using comma(,) as a separator and ignore any comma that is inside quotes(")
fieldSeparator : ,
fieldGrouper : "
The string to split is : "1","2",3,"4,5"
I am able to achieve it as follows :
String record = "\"1\",\"2\",3,\"4,5\"";
String[] tokens = record.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
Output :
"1"
"2"
3
"4,5"
Now the challenge is that the fieldGrouper(") should not be a part of the split tokens. I am unable to figure out the regex for this.
The expected output of the split is :
1
2
3
4,5

""exception which will likely appear sooner or later.