I have a csv file that I would like to use the String split()
method on. I want each element of the array returned by split()
to be the comma separated values in the csv. However, there are other commas in the csv file.
Fortunately, these other commas are escaped like '\,'
I am having trouble getting the right regex for the split()
method. I want to split by commas that are not preceded by the escape character.
My current code is:
String[] columns = new String[CONST];
columns = someString.split("*^\\,*");
To me this says: split by a comma but the character before the comma must not be the escape character. Any number of characters before or after the comma are allowed.
- How do I get the correct regular expression?