Java 从字符串中提取url

Java 从字符串中提取url,java,regex,Java,Regex,我知道这个问题重复了很多次,但我找不到正确的答案 如果我有一个URL字符串,例如: “www.google.comwww.yahoo.comwww.ebay.com”(假设链接之间没有空格) 我想分别提取每个like并将它们放入数组中。我尝试使用regex,比如: String[] sp= parts.split("\\www"); System.out.println(parts[0]); 这没用!任何暗示都将不胜感激 描述 选项:不区分大小写 Match the re

我知道这个问题重复了很多次,但我找不到正确的答案

如果我有一个URL字符串,例如:

“www.google.comwww.yahoo.comwww.ebay.com”(假设链接之间没有空格)

我想分别提取每个like并将它们放入数组中。我尝试使用regex,比如:

    String[] sp= parts.split("\\www");
    System.out.println(parts[0]);
这没用!任何暗示都将不胜感激


描述 选项:不区分大小写

Match the regular expression below and capture its match into backreference number 1 «(www\.((?!www\.).)*)»
    Match the characters “www” literally «www»
    Match the character “.” literally «\.»
    Match the regular expression below and capture its match into backreference number 2 «((?!www\.).)*»
        Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
        Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
        Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!www\.)»
        Match the characters “www” literally «www»
        Match the character “.” literally «\.»
    Match any single character that is not a line break character «.»

JAVA


描述 选项:不区分大小写

Match the regular expression below and capture its match into backreference number 1 «(www\.((?!www\.).)*)»
    Match the characters “www” literally «www»
    Match the character “.” literally «\.»
    Match the regular expression below and capture its match into backreference number 2 «((?!www\.).)*»
        Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
        Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
        Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!www\.)»
        Match the characters “www” literally «www»
        Match the character “.” literally «\.»
    Match any single character that is not a line break character «.»

JAVA
您也可以使用基本字符串方法将
com www
分解为
com www
,然后简单地在空格上拆分:

    String urlString = "www.google.comwww.yahoo.comwww.ebay.com";
    String[] urlArray = urlString.replaceAll(".comwww.", ".com www.").split(" ");
    System.out.println(Arrays.toString(urlArray)); // [www.google.com, www.yahoo.com, www.ebay.com]

您也可以使用基本字符串方法将
com www
分解为
com www
,然后简单地在空格上拆分:

    String urlString = "www.google.comwww.yahoo.comwww.ebay.com";
    String[] urlArray = urlString.replaceAll(".comwww.", ".com www.").split(" ");
    System.out.println(Arrays.toString(urlArray)); // [www.google.com, www.yahoo.com, www.ebay.com]

这在一般情况下是不可能的,因为整个字符串在技术上是有效的域名。
parts
是数组吗?您正在将拆分版本的
parts
放入一个名为
sp
的数组中,但您正在从
parts
打印出来。这通常是不可能的,因为整个字符串在技术上是有效的域名。
parts
是数组吗?您正在将拆分版本的
部件
放入一个名为
sp
的数组中,但您正在从
部件
打印出来。