java - 第: How to retrieve "href" value from <a> link

标签 java jsp freemarker

我正在尝试从 Freemarker 中的链接检索 href 值,如下所示:

<a href="http://www.example.com" class="some-class">Test</a>

最佳答案

我尝试使用模式进行检索。你可以尝试一下

String str = "<a href=\"http://www.example.com\" class=\"some-class\">Test</a>";
Pattern pattern = Pattern.compile("(href=\"(.*?)\")");
Matcher macther = pattern.matcher(str);
if(macther.find()){
    System.out.println(macther.group(1).substring(5));
}

关于java - 第: How to retrieve "href" value from <a> link,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41100980/

相关文章:

java - JPA。 JoinTable 和两个 JoinColumns

java - 如何使用 JSTL 遍历字符串中的每个字符?

javascript - 使用数组构建 HTML 表单

java - JSTL foreach - 如何从最后一个循环到第一个

java - 使用 freemarker 重新定位光标

java - 生成的 html 显示 ?而不是国际字符

java - is-hibernate 中的关系

java - 在 Twitter/Apache Storm 中共享资源

java - JSP 和 MVC 最佳实践

java - 将 #recurse 与 XML 以外的树一起使用时,我需要数据模型的 Freemarker 文档