当前位置: 代码迷 >> J2EE >> 给个正则解决方案
  详细解决方案

给个正则解决方案

热度:5129   发布时间:2013-02-25 21:40:27.0
给个正则
我有一段  ”类型:</b><em><a href="/attractions-d19-s05-rdp1/huangshan:attractions">自然景观</a>&nbsp;&nbsp;</em></li></ul>“
我要用正则匹配到“自然景观”,且/attractions-d19-s05-rdp1/huangshan:attractions这个值不确定,求大神给个正则表达式

String reg="<a.*?>(.*?)</a>";
String html=你的html字符串;
Matcher m=Pattern.compile(reg).matcher(html);
if(m.find())
  System.out.println(m.group(1));
引用:
.innerHTML  不直接可以获得了吗?
在类里做吗?取<a> </a> 二者之间的不就可以了
String ss = s.replaceAll("\\<a\\>(.*?)\\</a\\>", "$1");

呃 是.innerText吧。。。.innerHTML  不直接可以获得了吗?
在类里做吗?取<a> </a> 二者之间的不就可以了
String ss = s.replaceAll("\\<a\\>(.*?)\\</a\\>", "$1");String str = "”类型:</b><em><a href=\"/attractions-d19-s05-rdp1/huangshan:attractions\">自然景观</a>&nbsp;&nbsp;</em></li></ul>“";

System.out.println(str.replaceAll(".*<em><a.*?>(.*?)</a>.*", "$1"));
  相关解决方案