Reputation: 13
I'm looking for java regex to split the inputString while ignoring delimiters between brackets/multiple brackets.
Java code:
Pattern p = Pattern.compile("[,regex?]");
String[] desiredOutput =p.split(inputString);
for example:
inputString="1,{2,{3},4},{4,5},6";
desiredOutput with ; delimiter:
1;{2,{3},4};{4,5};6
Thnx!
Upvotes: 1
Views: 1523
Reputation: 420951
That's not possible using regular expressions.
The expression would have to match strings with balanced brackets. (Which is not a regular language.)
You need to use some other parsing technique or do it manually by counting {
and }
.
Upvotes: 5