You can use this code:
String line = "a=1,b=\"1,2\",c=\"[d=1,e=1,11]\""; String[] tokens = line.split(",(?=(([^\"]*\"){2})*[^\"]*$)"); for (String t : tokens) System.out.println("> " + t);
This regular expression matches only a comma if it is followed by an even number of double quotes. This way, the commas inside the double quote are not matched, however, all external commas are used to separate your input.
PS: This will only work for balanced lines. this will not work: "a=1,b=\"1,2" , because the double quote is not balanced.
OUTPUT:
> a=1 > b="1,2" > c="[d=1,e=1,11]"
source share