1. Replace HTML tags
Copy the code code as follows:
replaceAll("//&[a-zA-Z]{0,9};", "").replaceAll("<[^>]*>", "/n/t")
The source code is as follows:
Copy the code code as follows:
/**
* String replacement
*/
package com.you.model;
/**
* HTML tag replacement
* @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'>Serial number</th><th colspan='2'>李思</ th><th>Zhao Liu</th></tr><table>";
/**
* Replace HTML tags
*/
String subStr = str.replaceAll("//&[a-zA-Z]{0,9};", "").replaceAll("<[^>]*>", "/n/t");
/**
* Print the replaced string
*/
System.out.println("Print the replaced string: " + subStr);
}
}
2. The running results are as follows
Print the replaced string:
serial number
John Doe
Zhao Liu