Consider i have a String like this :
String str = "a,b,c,d," + char1 + "e,f" + char2 + ",g,h,i,j";
How to split every thing with ,
avoid every thing between char1
and char2
that not ,
.
I can use this regex ,(?![^()]*\\))
to split only if char1 = '('
and char2 = ')'
like this :
char char1 = '(', char2 = ')';
String str = "a,b,c,d," + char1 + "e,f,g" + char2 + ",h";
String s2[] = str.toString().split(",(?![^()]*\\))");
I get this result :
a
b
c
d
e,f,g
h
So how to generalize this to use any char in char1
and char2
.
Thank you.