去除HTML标签

 /**
	 * 去除str中的HTML标签
	 * 
	 * @param str
	 * @return
	 */
	public static String formatHtml(String str) {
		if (str == null) {
			return "";
		}
		str = str.toLowerCase();
		str = str.replaceAll("</?span[^>]*>", "");
		str = str.replaceAll("&#[^>]*;", "");
		str = str.replaceAll("</?marquee[^>]*>", "");
		str = str.replaceAll("</?object[^>]*>", "");
		str = str.replaceAll("</?param[^>]*>", "");
		str = str.replaceAll("</?embed[^>]*>", "");
		str = str.replaceAll("</?table[^>]*>", "");
		str = str.replaceAll("&nbsp;", "");
		str = str.replaceAll("</?tr[^>]*>", "");
		str = str.replaceAll("</?th[^>]*>", "");
		str = str.replaceAll("</?p[^>]*>", "");
		str = str.replaceAll("</?a[^>]*>", "");
		str = str.replaceAll("</?img[^>]*>", "");
		str = str.replaceAll("</?tbody[^>]*>", "");
		str = str.replaceAll("</?li[^>]*>", "");
		str = str.replaceAll("</?div[^>]*>", "");
		str = str.replaceAll("</?td[^>]*>", "");
		str = str.replaceAll("</?script[^>]*>", "");
		str = str.replaceAll("(javascript|jscript|vbscript|vbs):", "");
		str = str.replaceAll("on(mouse|exit|error|click|key)", "");
		str = str.replaceAll("<\\?xml[^>]*>", "");
		str = str.replaceAll("<\\?[a-z]+:[^>]*>", "");
		str = str.replaceAll("</?font[^>]*>", "");
		str = str.replaceAll("</?b[^>]*>", "");
		str = str.replaceAll("</?u[^>]*>", "");
		str = str.replaceAll("</?i[^>]*>", "");
		str = str.replaceAll("</?strong[^>]*>", "");
		str = str.replaceAll("</?(a|A)( .*?>|>)", "");
		return str;
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值