I'm trying to split strings in a rather specific way. I've been fooling around using the .split()
and .replaceall()
methods, but I can't get it right.
Here are a couple of examples of the strings I need to split, followed by how they must be after the splitting. A ,
signifies a new string in the array.
Example 1: "(and (or (can-hit-robot) (wall) ) (can-hit-robot) (wall) ) )"
"(and", "(or", "(can-hit-robot)", "(wall)", ")", "(can-hit-robot)", "(wall)", ")"
Example 2: "(seq (shoot) (if (can-hit-robot) (shoot) (move) ) )"
"(seq", "(shoot)", "(if", "(can-hit-robot)", "(shoot)", "(move)", ")", ")"
Example 3: "(while(wall)(if (can-hit-robot)(shoot)(move)))"
"(while", "(wall)", "(if", "(can-hit-robot)", "(shoot)", "(move)", ")", ")"
Any help would be hugely appreciated!