假设:
String one = "show ip interface brief | include 1234**\n Gi1/23.1234 xxx.225.xxx.106 YES manual up up";
我想拆分
Gi1/23.1234 xxx.225.xxx.106 YES manual up up
进入不同的令牌并删除
show ip interface brief | include 1234**
输出应为:
String[] tokens = ["Gi1/23.1234", "xxx.225.xxx.106", "Yes", "manual", "up", "up"]
答案 0 :(得分:0)
您可以在这里同时使用String
的方法replaceAll
和split
。
String one = "show ip interface brief | include 1234**\n Gi1/23.1234 xxx.225.xxx.106 YES manual up up";
String[] tokens = one.replaceAll("[^\\n]+\\n\\s*", "").split("\\s+");
System.out.println(Arrays.toString(tokens));
输出
[Gi1/23.1234, xxx.225.xxx.106, YES, manual, up, up]