Java splits a line ignoring any delimiters between brackets
I am looking for java regex to split inputString while ignoring delimiters between brackets / multiple brackets.
Java code:
Pattern p = Pattern.compile("[,regex?]");
String[] desiredOutput =p.split(inputString);
eg:
inputString="1,{2,{3},4},{4,5},6";
requiredOutput with; Separator:
1;{2,{3},4};{4,5};6
Thnx!
+1
user1262381
source
to share
1 answer
This is not possible with regular expressions.
The expression must match strings with balanced parentheses. (Which is not common language.)
You need to use some other parsing method or do it manually by counting {
and }
.
+5
aioobe
source
to share