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...

24,192 Responses

  1. Dwayneseisa表示:

    kamagra kopen nederland kamagra kopen nederland Kamagra

  2. Kennethslity表示:

    https://generic100mgeasy.shop/# Cheap Viagra 100mg

  3. GregoryJough表示:

    Buy generic 100mg Viagra online: Generic100mgEasy – buy generic 100mg viagra online

  4. Paint the tip black for pencil lead, and paint the remainder light tan.

  5. TerryDus表示:

    http://tadalafileasybuy.com/# Tadalafil Easy Buy

  6. TerryDus表示:

    https://kamagrakopen.pro/# KamagraKopen.pro

  7. Kennethslity表示:

    http://generic100mgeasy.com/# Generic100mgEasy

  8. GregoryJough表示:

    Kamagra Kopen: kamagra gel kopen – Kamagra Kopen

  9. Kennethslity表示:

    https://generic100mgeasy.shop/# Generic100mgEasy

  10. Dwayneseisa表示:

    cialis without a doctor prescription cialis without a doctor prescription cialis without a doctor prescription

  11. WilliamNop表示:

    TadalafilEasyBuy.com: Tadalafil Easy Buy – Tadalafil Easy Buy

  12. Kennethslity表示:

    https://kamagrakopen.pro/# KamagraKopen.pro

  13. Dwayneseisa表示:

    TadalafilEasyBuy.com Tadalafil price Cialis 20mg price in USA

  14. TerryDus表示:

    http://generic100mgeasy.com/# Generic 100mg Easy

  15. Kennethslity表示:

    https://generic100mgeasy.com/# Generic100mgEasy

  16. The Union Budget triggers the Bull Run in the market bringing back the hope amongst the investors.

  17. GregoryJough表示:

    kamagra gel kopen: kamagra kopen nederland – Kamagra Kopen

  18. WilliamNop表示:

    kamagra pillen kopen: Officiele Kamagra van Nederland – kamagra kopen nederland

  19. WilliamNop表示:

    Generic Tadalafil 20mg price: cialis without a doctor prescription – cialis without a doctor prescription

  20. GregoryJough表示:

    TadalafilEasyBuy.com: Tadalafil Easy Buy – cialis without a doctor prescription

  21. TerryDus表示:

    https://generic100mgeasy.shop/# Cheap Sildenafil 100mg

  22. Dwayneseisa表示:

    Generic 100mg Easy cheapest viagra viagra canada

  23. TerryDus表示:

    https://tadalafileasybuy.shop/# TadalafilEasyBuy.com

  24. Richardnak表示:

    где продать быстро аккаунты купить аккаунт социальные сети

  25. Kennethslity表示:

    https://generic100mgeasy.com/# buy generic 100mg viagra online

  26. GregoryJough表示:

    Generic 100mg Easy: buy generic 100mg viagra online – Generic100mgEasy

  27. Sidious offered Skywalker an ultimatum to enter his service or die, and proceeded to make use of his Pressure-derived powers to torture and threaten to kill Skywalker when the latter refused to embrace the dark aspect of the Drive.

  28. GregoryJough表示:

    Cialis over the counter: Tadalafil Easy Buy – cialis without a doctor prescription

  29. WilliamNop表示:

    Tadalafil Easy Buy: Tadalafil Easy Buy – Tadalafil Easy Buy

  30. WilliamNop表示:

    Generic 100mg Easy: Generic 100mg Easy – buy generic 100mg viagra online

發佈留言

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