I would like to split the line as follows:
String s = "dotimes [sum 1 2] [dotimes [sum 1 2] [sum 1 3]]"
Result:
{"dotimes", "[sum 1 2]", "[dotimes [sum 1 2] [sum 1 3]]"
I tried using this regex:
s.split("\\s(?=\\[)|(?<=\\])\\s")
But this leads to the following:
dotimes
[sum 1 2]
[dotimes
[sum 1 2]
[sum 1 3]]
Is there a way to split the string the way I want to use regex?
source
share