Java中替换HTML标签的方法

1、替换HTML标签

replaceAll("\&[a-zA-Z]{0,9};", "").replaceAll("<[^>]*>", "
	")

源码如下:

/**
 * 字符串替换
 */
package com.you.model;

/**
 * HTML标签替换
 * @author YHD
 * @version
 */
public class StrReplace {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		String str = " <table border='1' cellpadding='1' cellspacing='1'><tr><th rowspan='2'>序号</th><th colspan='2'>李四</th><th>赵六</th></tr><table>";
		/**
		 * 替换HTML标签
		 */
		String subStr = str.replaceAll("\&[a-zA-Z]{0,9};", "").replaceAll("<[^>]*>", "
	");
		/**
		 * 打印替换后的字符串
		 */
		System.out.println("打印替换后的字符串:" + subStr);
	}

}

2、运行结果如下

打印替换后的字符串: 
	
	
	序号
	
	李四
	
	赵六


原文地址:https://www.cnblogs.com/hzcya1995/p/13315362.html