日期:2014-05-20  浏览次数:20759 次

去除字符串
Cont:<a target="_blank" href="http://roll.sports.sina.com.cn/s_eam2013_all/index.shtml">滚动新闻</a>
这个是我的输出结果,我现在只想留下Cont:滚动新闻,该怎么写

------解决方案--------------------
如果只是去掉<>之间的字符的话,可以这样:
String string = "Cont:<a target=\"_blank\" href=\"http://roll.sports.sina.com.cn/s_eam2013_all/index.shtml\">滚动新闻</a>";
string = string.replaceAll("<.*?>", "");
System.out.println(string);

供参考^_^
------解决方案--------------------
String str = "Cont:<a target=\"_blank\" href=\"http://roll.sports.sina.com.cn/s_eam2013_all/index.shtml\">滚动新闻</a>";
String exp = "<([^>]*)>";
Pattern pattern = Pattern.compile(exp);
Matcher matcher = pattern.matcher(str);
String result = matcher.replaceAll("");
System.out.println(result);