<td width="82">2011-04-05</td>
<td width="45">20:37</td>
<td align="left" width="339">
<a href="#" onmouseout="hideTip()" onmouseover="showTip('帮忙@0',event)">
<font color=#FF0000></font>
</a>
<a href="#" onmouseout="hideTip()" onmouseover="showTip('呵呵',event)">
<font color=#0000FF> 张三 </font>
</a>
哈哈,
<b>大笑了</b>
</td>以上是一个String 现在我需要用到String.replaceAll()方法,把标签等不要的内容全部替换掉,剩下所需的东西..
"2011-04-05 20:37 张三哈哈,大笑了" 这是取到最后的内容主要用到就是一个正则表达式..
<td width="45">20:37</td>
<td align="left" width="339">
<a href="#" onmouseout="hideTip()" onmouseover="showTip('帮忙@0',event)">
<font color=#FF0000></font>
</a>
<a href="#" onmouseout="hideTip()" onmouseover="showTip('呵呵',event)">
<font color=#0000FF> 张三 </font>
</a>
哈哈,
<b>大笑了</b>
</td>以上是一个String 现在我需要用到String.replaceAll()方法,把标签等不要的内容全部替换掉,剩下所需的东西..
"2011-04-05 20:37 张三哈哈,大笑了" 这是取到最后的内容主要用到就是一个正则表达式..
解决方案 »
- getHibernateTemplate().save(ad)奇怪情况,无语了。
- 在hibernate的使用中我一些问题感到迷惑!!!
- 一个源代码5M的项目大不大?
- tomcat虚拟主机的配置=====================高分求解
- ■■struts对多表多记录的FormBean应当如何设计呢,请给意见吧?■■
- 寻求j2ee1.4或weblogin7.0以上版本的服务配置及JSP EJB的发布方面的资料
- 今年做课题,但不知做什么好?哪位指点一下?
- 关于如何高效地组合和使用EJB?^_^
- JBuilder 简单问题:如何将JTextField控件中的数据保存到数据库?
- 如何使返回的记录集RS转换成XML
- struts2.2+spring 2.5+hibernate3 Exception!
- 要提供给第三方使用的不开源的底层框架,使用什么混淆器混淆代码比较好?
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class test2 { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "<td width=\"82\">2011-04-05</td><td width=\"45\">20:37</td><font color=#0000FF> 张三 </font></a>哈哈,<b>大笑了</b>";
String regex = "(?<=>)[^<]+?(?=<)";
Matcher m = Pattern.compile(regex).matcher(str);
while(m.find()){
System.out.println(m.group());
}
}}have a try
String htmlStr = inputString;
String textStr = "";
java.util.regex.Pattern p_html;
java.util.regex.Matcher m_html;
try {
String regEx_html = "<[^>]+>";
p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); textStr = htmlStr; } catch (Exception e) {
System.err.println("Html2Text: " + e.getMessage());
} return textStr;
} public static void main(String[] args) {
String html = "<td width=\"82\">2011-04-05</td><td width=\"45\">20:37</td>"
+ "<td align=\"left\" width=\"339\">"
+ "<a href=\"#\" onmouseout=\"hideTip()\" onmouseover=\"showTip('帮忙@0',event)\">"
+ "<font color=#FF0000></font></a>"
+ "<a href=\"#\" onmouseout=\"hideTip()\" onmouseover=\"showTip('呵呵',event)\">"
+ "<font color=#0000FF> 张三 </font></a>哈哈,<b>大笑了</b></td>";
System.out.println(delHtml(html));
}
}