Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果在java中找到任何字符,如何拆分字符串_Java_Regex_String_Split_Tokenize - Fatal编程技术网

如果在java中找到任何字符,如何拆分字符串

如果在java中找到任何字符,如何拆分字符串,java,regex,string,split,tokenize,Java,Regex,String,Split,Tokenize,鉴于: 我想分手 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[] to

鉴于:

我想分手

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"]
输出

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));

好你说对了。使用字符串类的split()方法,您的帖子几乎无法阅读。不管怎样,您是否尝试过任何方法,比如从字符串类中拆分
split
方法?我们能看看你们的尝试吗?是的,我已经尝试过了,但我无法从吉尔开始分割第二行。。因为拆分方法不拆分“|”。如果你能帮上忙的话,那就请你把
regex
字符
“|”
转义出来。示例:
string.split(“\\\\”)
[Gi1/23.1234, xxx.225.xxx.106, YES, manual, up, up]