Java中替换HTML标签的方法代码

1、替换HTML标签

复制代码 代码如下:

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

源码如下:

复制代码 代码如下:

/**
 * 字符串替换
 */
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("<[^>]*>", "\n\t");
  /**
   * 打印替换后的字符串
   */
  System.out.println("打印替换后的字符串:" + subStr);
 }

}

2、运行结果如下

打印替换后的字符串:    
    序号 

    李四 

    赵六