Java + JS去除網頁HTML標籤

同樣是工作上用到,在前(Javascript)、後端(Java、JSP)同樣都有的一個需求,就是必須將讀入的字串去除HTML Tag,以下是兩個範例:

var HTML = "";
HTML+= "<p>HTML P Tag String</p>";
HTML+= "<p><a href='/test/link.html'>HTML A Tag String</a></p>";

var htmlTagPattern = /<{1}[^>]{1,}>{1}/g; //HTML Tag Pattern
var htmlSplit = HTML.replace(htmlTagPattern, ""); //移除HTML Tag

console.log("htmlSplit : " , htmlSplit); //輸出htmlSplit :  HTML P Tag StringHTML A Tag String
package CDIT.stanley;
public class trimHTML {
	public static void main(String[] args) {
		String HTML = "";
		HTML+= "<p>HTML P Tag String</p>";
		HTML+= "<p><a href='/test/link.html'>HTML A Tag String</a></p>";
		
		String htmlTagPattern = "<{1}[^>]{1,}>{1}"; //HTML Tag Pattern		
		String htmlSplit = HTML.replaceAll(htmlTagPattern, ""); //移除HTML Tag
		
		System.out.println("htmlSplit : " + htmlSplit); //輸出htmlSplit : HTML P Tag StringHTML A Tag String
	}
}

You may also like...

18,404 Responses

  1. WilliamDen表示:

    https://gramster.ru/# пин ап вход

  2. вывод из запоя дешево ростов-на-дону вывод из запоя дешево ростов-на-дону .

  3. Jamesboype表示:

    https://gramster.ru/# pinup 2025

  4. DarrenWab表示:

    пин ап казино Gramster gramster.ru

  5. WilliamDen表示:

    https://gramster.ru/# pinup 2025

  6. DarrenWab表示:

    пин ап вход gramster.ru пин ап казино зеркало

  7. WilliamDen表示:

    https://gramster.ru/# пин ап казино

  8. WilliamDen表示:

    https://gramster.ru/# gramster.ru

  9. Jamesboype表示:

    http://gramster.ru/# pinup 2025

  10. Jeffreywex表示:

    http://gramster.ru/# пин ап зеркало

  11. Jeffreywex表示:

    https://gramster.ru/# gramster.ru

  12. Make sure your selected attorney is a member of this organization, not because it screens them in any way (there are no membership requirements), but because the organization itself stays on top of franchise law and offers seminars and other current franchise information for members.

  13. WilliamDen表示:

    https://gramster.ru/# pinup 2025

  14. Jamesboype表示:

    http://gramster.ru/# пин ап казино

  15. Jeffreywex表示:

    https://gramster.ru/# gramster.ru

  16. Jeffreywex表示:

    https://gramster.ru/# пин ап зеркало

  17. RobertCow表示:

    pinup 2025: gramster.ru – пин ап

  18. RobertCow表示:

    pinup 2025: Gramster – pinup 2025

  19. Amaranth Advisors collapse is certainly one of the most important hedge fund collapses in historical past and on the time (2006) largest identified trading losses.

  20. 往路 優勝表示:

    By implementing features that promote digital well-being, such as screen time management and content filters, they can mitigate the potential risks associated with technology use.

  21. Jamesboype表示:

    http://gramster.ru/# gramster.ru

  22. The desire to explore new places, trying into the unseen and untouched aspects of nature and merely indulging your self in a place that’s not acquainted to you is something that makes a whole traveller.

  23. RobertCow表示:

    пин ап казино: Gramster – пин ап казино официальный сайт

  24. DarrenWab表示:

    пин ап зеркало gramster.ru пин ап вход

  25. DarrenWab表示:

    пин ап казино зеркало gramster gramster.ru

  26. Natural and normal. How much threat are you prepared to take?

  27. So the chance of making dangerous decisions increases.

  28. Specific investment capabilities embody convertibles, asset backed securities, credit score, loans, structured credit, and equities.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。