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,455 Responses

  1. WilliamNop表示:

    buy generic 100mg viagra online: Generic 100mg Easy – Sildenafil Citrate Tablets 100mg

  2. Dwayneseisa表示:

    Kamagra Kamagra Kopen Online kamagra 100mg kopen

  3. Kennethslity表示:

    https://kamagrakopen.pro/# kamagra pillen kopen

  4. GregoryJough表示:

    kamagra jelly kopen: kamagra pillen kopen – Kamagra Kopen

  5. WilliamNop表示:

    TadalafilEasyBuy.com: Tadalafil Easy Buy – Buy Tadalafil 5mg

  6. WilliamNop表示:

    TadalafilEasyBuy.com: п»їcialis generic – TadalafilEasyBuy.com

  7. TerryDus表示:

    https://generic100mgeasy.shop/# over the counter sildenafil

  8. GregoryJough表示:

    TadalafilEasyBuy.com: TadalafilEasyBuy.com – cialis without a doctor prescription

  9. Kennethslity表示:

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

  10. Dwayneseisa表示:

    Kamagra Kamagra Kamagra Kopen

  11. WilliamNop表示:

    Generic 100mg Easy: Generic100mgEasy – Generic100mgEasy

  12. WilliamNop表示:

    kamagra kopen nederland: kamagra gel kopen – kamagra 100mg kopen

  13. TerryDus表示:

    https://kamagrakopen.pro/# Officiele Kamagra van Nederland

  14. TerryDus表示:

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

  15. GregoryJough表示:

    Tadalafil Easy Buy: Tadalafil Easy Buy – TadalafilEasyBuy.com

  16. GregoryJough表示:

    Tadalafil Easy Buy: Tadalafil Easy Buy – TadalafilEasyBuy.com

  17. Kennethslity表示:

    https://tadalafileasybuy.shop/# Tadalafil Easy Buy

  18. WilliamNop表示:

    Sildenafil 100mg price: Sildenafil Citrate Tablets 100mg – buy generic 100mg viagra online

  19. Dwayneseisa表示:

    sildenafil 50 mg price Generic100mgEasy Generic 100mg Easy

  20. WilliamNop表示:

    Generic 100mg Easy: Generic100mgEasy – Generic 100mg Easy

  21. TerryDus表示:

    https://generic100mgeasy.shop/# Viagra tablet online

  22. TerryDus表示:

    https://generic100mgeasy.com/# Generic Viagra for sale

  23. GregoryJough表示:

    Cialis 20mg price in USA: Tadalafil Easy Buy – Tadalafil Easy Buy

  24. Dwayneseisa表示:

    Tadalafil price TadalafilEasyBuy.com Cialis over the counter

  25. Kennethslity表示:

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

  26. WilliamNop表示:

    buy generic 100mg viagra online: Generic100mgEasy – Generic100mgEasy

  27. Kennethslity表示:

    https://generic100mgeasy.shop/# Generic100mgEasy

  28. Kennethslity表示:

    http://generic100mgeasy.com/# Viagra without a doctor prescription Canada

  29. TerryDus表示:

    https://kamagrakopen.pro/# kamagra kopen nederland

  30. GregoryJough表示:

    Tadalafil Easy Buy: TadalafilEasyBuy.com – TadalafilEasyBuy.com

發佈留言

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