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 - Fatal编程技术网

Java 分离多个分离器

Java 分离多个分离器,java,regex,Java,Regex,我有一个字符串,其中包含由|分隔的URL,如下所示: http://...|http://...|http://... 但是在一些URL中,我可能有caracheter|,因此我可以使用.split(“| http://”)对其进行拆分,但问题是,在一些URL中包含另一个类似这样的URL http://...|http://..=http://...=http://...|http://...=http%25253A%25252F%25252F... 那么如何使用regex按http://or=

我有一个字符串,其中包含由|分隔的URL,如下所示:

http://...|http://...|http://...

但是在一些URL中,我可能有caracheter|,因此我可以使用.split(“| http://”)对其进行拆分,但问题是,在一些URL中包含另一个类似这样的URL

http://...|http://..=http://...=http://...|http://...=http%25253A%25252F%25252F...


那么如何使用regex按http://or=http://or=http%25253A%25252F%25252F进行拆分呢?

您可以使用以下代码:

String str = "http://www.google.com|https://support.microsoft.com/en-us/kb/301982|http://www.tutorialspoint.com/java/lang/string_split.htm";
String delimiters = "\\|(?=http)";

// analyzing the string 
String[] urls = str.split(delimiters);

// prints the number of tokens
System.out.println("Count of urls= " + urls.length);

for(String url: urls) {
    System.out.println(url);
} 
它将在
|
上拆分,然后在
http
上拆分。此示例的输出为:

Count of urls = 3
http://www.google.com
https://support.microsoft.com/en-us/kb/301982
http://www.tutorialspoint.com/java/lang/string_split.htm

您可以尝试以下代码:

// As your question in this string contains three https
String httpStr = "http://...|http://..=http://...=http://...|http://...=http%25253A%25252F%25252F...";
// Split the string with 'http' that preceded by |
String[] https = httpStr.split("(?<=\\|)http");
for (String http : https) {
    System.out.println("http = http" + http);
}

分享你的研究成果对每个人都有帮助。告诉我们您尝试了什么,以及为什么它不能满足您的需求。这表明你花了时间来帮助自己,它使我们避免重复显而易见的答案,最重要的是,它帮助你得到一个更具体和相关的答案!还看到我的答案有什么反馈吗?
http = http://...|
http = http://..=http://...=http://...|
http = http://...=http%25253A%25252F%25252F...