Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.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正则表达式提取超链接的Url(不使用模式匹配器)(Java正则表达式)?_Java_Regex - Fatal编程技术网

Java正则表达式提取超链接的Url(不使用模式匹配器)(Java正则表达式)?

Java正则表达式提取超链接的Url(不使用模式匹配器)(Java正则表达式)?,java,regex,Java,Regex,如何捕获URLHEF,但不使用模式和匹配器 我使用的是Gwt平台&它没有模式和匹配器 这段代码还可以,但它使用了Pattern&Matcher public static String getTheUrlOfHref(String href){ Pattern p = Pattern.compile("href=\"(.*?)\""); Matcher m = p.matcher(href); String url = null; if (m.find()) {

如何捕获URLHEF,但不使用模式和匹配器

我使用的是Gwt平台&它没有
模式和匹配器

这段代码还可以,但它使用了Pattern&Matcher

public static String getTheUrlOfHref(String href){
    Pattern p = Pattern.compile("href=\"(.*?)\"");
    Matcher m = p.matcher(href);
    String url = null;
    if (m.find()) {
        url = m.group(1); // this variable should contain the link URL
    }
    return url;
}

因此,如何提取超链接的Url(不使用Pattern&Matcher)(Java正则表达式)?

如果您需要在客户端进行更多的字符串处理,那么您必须学习如何编写Javascript并将其合并到GWT生成的Javascript代码中

例如,见


如果您想在服务器端执行此操作,那么模式和匹配器就可以正常工作。

嗯,您可以删除所有不需要的内容

public static String getTheUrlOfHref(String href){
    href = href.replaceAll("^.*?href=\"", "");        // Remove everything before
                                                      // and including href="

    String url = test.substring(0,test.indexOf('"')); // Get everything till
                                                      // first " character
    return url;
}

我没有放任何东西来处理错误。我想你可以自己加上


或者可能:

public static String getTheUrlOfHref(String href){
    String url = href.replaceAll("^.*?href=\"([^\"]*)\".*", "$1");
    return url;
}

为什么不想使用模式和匹配器?它们是您在Java中使用正则表达式的方式。@HunterMcMillen请看。我不想为我的GWT添加程序包,简单来说太多了。我想他们说的是,他们使用的GWT版本中,
Pattern
Matcher
不可用。不,该方法在客户端和服务器之间共享。在客户机中,它没有模式类。它们不可用是因为GWT正在将代码编译成javascript以在客户机上运行,而不是因为它们在服务器上不可用。GWT应用程序的服务器端可以做任何java应用程序都能做的事情。服务器可以有模式,但客户端并不可怕,i=这比模式更好heavy@Tum嗯??模式会比那更快!