Method code to replace HTML tags in Java

  • 2020-04-01 02:58:44
  • OfStack

1. Replace HTML tags


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

Source as follows:



package com.you.model;

public class StrReplace {
 
 public static void main(String[] args) 
 {
  String str = " <table border='1' cellpadding='1' cellspacing='1'><tr><th rowspan='2'> The serial number </th><th colspan='2'> Li si </th><th> Zhao six </th></tr><table>";
  
  String subStr = str.replaceAll("\&[a-zA-Z]{0,9};", "").replaceAll("<[^>]*>", "nt");
  
  System.out.println(" Print the replaced string: " + subStr);
 }
}

2. The operation results are as follows

Print the alternate string:        
      The serial number  

      Li si  

      Zhao six  


Related articles: