我正在使用 java 来拆分形式的字符串:
String stringToSplit = "AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK";
我在用着
String[] tokens = stringToParse.split("\\s");
沿空白分割字符串,给出:
tokens = {"AAA","BBB","CCC", "DDD","EEE","FFF","GGG","HHH","III", "JJJ", "KKK"}
我现在需要做的是将它们中的大多数沿着空格分开,但在特定情况下还要保持一些字符串在一起。例如,当我拆分时,我希望“CCC DDD”和“III JJJ KKK”保持完整的字符串。所以我希望我的令牌数组是:
tokens = {"AAA","BBB","CCC DDD","EEE","FFF","GGG","HHH","III JJJ KKK"}
我会使用什么正则表达式?这可能吗?