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

  1. TerryDus表示:

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

  2. GregoryJough表示:

    Tadalafil Easy Buy: cialis without a doctor prescription – Tadalafil Easy Buy

  3. TerryDus表示:

    https://kamagrakopen.pro/# Kamagra Kopen Online

  4. Dwayneseisa表示:

    TadalafilEasyBuy.com Buy Tadalafil 20mg Tadalafil Easy Buy

  5. Kennethslity表示:

    https://kamagrakopen.pro/# kamagra 100mg kopen

  6. WilliamNop表示:

    buy generic 100mg viagra online: Order Viagra 50 mg online – Generic100mgEasy

  7. Dwayneseisa表示:

    Kamagra Officiele Kamagra van Nederland kamagra 100mg kopen

  8. TerryDus表示:

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

  9. GregoryJough表示:

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

  10. WilliamNop表示:

    Generic 100mg Easy: Generic 100mg Easy – Generic 100mg Easy

  11. WilliamNop表示:

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

  12. Kennethslity表示:

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

  13. Dwayneseisa表示:

    Kamagra Kamagra kamagra 100mg kopen

  14. TerryDus表示:

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

  15. TerryDus表示:

    https://generic100mgeasy.shop/# Generic 100mg Easy

  16. GregoryJough表示:

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

  17. Kennethslity表示:

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

  18. WilliamNop表示:

    Kamagra: kamagra pillen kopen – kamagra jelly kopen

  19. WilliamNop表示:

    generic sildenafil: buy viagra here – buy generic 100mg viagra online

  20. GregoryJough表示:

    Generic100mgEasy: Generic100mgEasy – sildenafil over the counter

  21. Kennethslity表示:

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

  22. Kennethslity表示:

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

  23. WilliamNop表示:

    Officiele Kamagra van Nederland: kamagra pillen kopen – Kamagra Kopen Online

  24. GregoryJough表示:

    Generic100mgEasy: Generic100mgEasy – Generic 100mg Easy

  25. Dwayneseisa表示:

    KamagraKopen.pro kamagra kopen nederland Kamagra Kopen

  26. GregoryJough表示:

    KamagraKopen.pro: KamagraKopen.pro – kamagra jelly kopen

  27. TerryDus表示:

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

  28. WilliamNop表示:

    Tadalafil Easy Buy: cheapest cialis – Tadalafil Easy Buy

發佈留言

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