JavaはテキストからHTMLタグを削除します



Java Remove Html Tags From Text



package com.yf.core.utils import java.util.regex.Matcher import java.util.regex.Pattern public class del_html{ public static String delHTMLTag(String htmlStr){ String regEx_script=']*?>[\s\S]*?' //Define the regular expression of script String regEx_style=']*?>[\s\S]*?' //Regular expression that defines style String regEx_html=']+>' //Regular expression that defines HTML tags Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE) Matcher m_script=p_script.matcher(htmlStr) htmlStr=m_script.replaceAll('') //Filter script tags Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE) Matcher m_style=p_style.matcher(htmlStr) htmlStr=m_style.replaceAll('') //Filter style tags Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE) Matcher m_html=p_html.matcher(htmlStr) htmlStr=m_html.replaceAll('') //Filter html tags return htmlStr.trim() //Return text string } public static void main(String[] args) { String name='This website, you can use the switch with parameters to request the content of the website when there is no script.
  • The page title is essential for the page, and it is also an important indicator of the spider index, you can consider the program dynamics Output.
  • Introduce the main style files, and import device-related style files according to the device type to support tablets and printers.
  • The front-end script sets the version through back-end variables to Conducive to the update of documents and static resources.
  • About the pre-global script, you need to do: huanhuanhuanhuanhuanhuan
    • If the page is not used as iframe content, to prevent malicious nesting, misleading or Phishing-related things. huanhuanhuanhuanhuanhuan
      • If you use the class name as a hook to tell the page program whether to support calling, you can further deal with it here.
      • For the old version of IE, here specifically means that the version is less than Old browsers equal to IE8, if you want to downgrade gracefully, you need to do pre-processing again.
      • If the page program depends on data to render, the pre-data is also recommended to be placed in This.
      • If the page depends on the script loader, you can add a loader script here.
      • For older browsers, you can use IE conditional comments with shim scripts and respond to provide Some additional feature support to reduce extra processing when writing code and maintain consistent access.
      • Page keywords and related instructions are also crucial if you do SEO.
      • If you also want to provide RSS and PING, please also provide them here.
      • For search engines, provide shortlinks to merge the revised and rewritten status.
  • –EOF–

    ' System.out.println(delHTMLTag(name)) } }