This article mainly introduces the method code of replacing HTML tags in Java, the need for friends can refer to the following
ReplaceAll ("\\&[a-za-z]{0,9};", "" "). ReplaceAll (" <[^>]*> "," \n\t ")
The source code is as follows:
/*** String Substitution*/ PackageCom.you.model; /*** HTML Tag replacement *@authorYHD *@version */ Public classStrreplace {/** * @paramargs*/ Public Static voidMain (string[] args) {String str= "<table border= ' 1 ' cellpadding= ' 1 ' cellspacing= ' 1 ' ><tr><th rowspan= ' 2 ' > serial number </th><th colspan= ' 2 ' > John Doe </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 result of operation is as follows
Print the replaced string:
Serial number
John doe
Zhao Liu
Method code for replacing HTML tags in Java