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

  1. GregoryJough表示:

    Kamagra: kamagra 100mg kopen – KamagraKopen.pro

  2. Dwayneseisa表示:

    kamagra kopen nederland kamagra pillen kopen kamagra kopen nederland

  3. Kennethslity表示:

    https://kamagrakopen.pro/# Kamagra Kopen

  4. WilliamNop表示:

    Officiele Kamagra van Nederland: kamagra kopen nederland – Kamagra

  5. WilliamNop表示:

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

  6. TerryDus表示:

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

  7. TerryDus表示:

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

  8. GregoryJough表示:

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

  9. Dwayneseisa表示:

    Kamagra Kamagra Kopen kamagra pillen kopen

  10. Kennethslity表示:

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

  11. WilliamNop表示:

    Tadalafil Easy Buy: Tadalafil Tablet – Tadalafil Easy Buy

  12. Kennethslity表示:

    https://generic100mgeasy.com/# Generic100mgEasy

  13. GregoryJough表示:

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

  14. TerryDus表示:

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

  15. Dwayneseisa表示:

    kamagra gel kopen Officiele Kamagra van Nederland Kamagra

  16. Kennethslity表示:

    http://generic100mgeasy.com/# buy Viagra over the counter

  17. WilliamNop表示:

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

  18. WilliamNop表示:

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

  19. GregoryJough表示:

    Generic100mgEasy: Generic100mgEasy – Generic100mgEasy

  20. TerryDus表示:

    https://tadalafileasybuy.shop/# Cialis 20mg price in USA

  21. TerryDus表示:

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

  22. Dwayneseisa表示:

    TadalafilEasyBuy.com TadalafilEasyBuy.com Tadalafil Easy Buy

  23. GregoryJough表示:

    Generic 100mg Easy: buy generic 100mg viagra online – over the counter sildenafil

  24. WilliamNop表示:

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

  25. WilliamNop表示:

    cialis without a doctor prescription: cialis without a doctor prescription – Buy Tadalafil 10mg

  26. Kennethslity表示:

    https://tadalafileasybuy.shop/# cialis without a doctor prescription

  27. GregoryJough表示:

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

  28. TerryDus表示:

    http://generic100mgeasy.com/# Generic100mgEasy

  29. TerryDus表示:

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

發佈回覆給「TerryDus」的留言 取消回覆

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