This question already has answers here:
Closed 4 years ago.
I would like to split a string in java on a comma(,) but whenever the comma(,) is in between some parenthesis, it should not be split.
e.g. The string :
"life, would, (last , if ), all"
Should yield:
-life
-would
-(last , if )
-all
When I use :
String text = "life, would, (last , if ), all"
text.split(",");
I end up dividing the whole text even the (last , if ) I can see that split takes a regex but I can't seem to think of how to make it do the job.