我正在尝试以一种相当具体的方式拆分字符串。我一直在鬼混使用.split()
and.replaceall()
方法,但我做错了。
以下是我需要拆分的几个字符串示例,然后是拆分后的字符串。A,
表示数组中的新字符串。
示例 1:"(and (or (can-hit-robot) (wall) ) (can-hit-robot) (wall) ) )"
"(and", "(or", "(can-hit-robot)", "(wall)", ")", "(can-hit-robot)", "(wall)", ")"
示例 2:"(seq (shoot) (if (can-hit-robot) (shoot) (move) ) )"
"(seq", "(shoot)", "(if", "(can-hit-robot)", "(shoot)", "(move)", ")", ")"
示例 3: "(while(wall)(if (can-hit-robot)(shoot)(move)))"
"(while", "(wall)", "(if", "(can-hit-robot)", "(shoot)", "(move)", ")", ")"
任何帮助将不胜感激!