当前位置: 代码迷 >> Java Web开发 >> java 如何用正则获取html中的值
  详细解决方案

java 如何用正则获取html中的值

热度:2418   发布时间:2013-02-25 21:19:45.0
java 怎么用正则获取html中的值
String pageContent = "<a href='/Patent/01127847' target='_blank'>
<a href='/Patent/01127821' target='_blank'>
<a href='/Patent/01127832' target='_blank'>";
 省略其他标签

Pattern pattern2 = Pattern.compile("(<a href='/Patent/([\\s\\S]*?)target='_blank'>)");
Matcher matcher = pattern2.matcher(pageContent);
while (matcher.find()) {
  strPage = matcher.group();
}

要怎么样拿到01127847,01127821,01127832



上面哪里出错了 


------解决方案--------------------------------------------------------
看不明白呀
------解决方案--------------------------------------------------------
Java code
        String pageContent = "<a href='/Patent/01127847' target='_blank'><a href='/Patent/01127821' target='_blank'><a href='/Patent/01127832' target='_blank'>";                     Pattern pattern2 = Pattern.compile("(?:<a\\s+href='/Patent/([\\s\\S]*?)'\\s+target='_blank'>)");        Matcher matcher = pattern2.matcher(pageContent);        while (matcher.find()) {          System.out.println(matcher.group(1));        }
  相关解决方案