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

  1. WilliamNop表示:

    KamagraKopen.pro: kamagra jelly kopen – kamagra kopen nederland

  2. GregoryJough表示:

    Generic 100mg Easy: Viagra without a doctor prescription Canada – buy generic 100mg viagra online

  3. Dwayneseisa表示:

    kamagra jelly kopen Kamagra Kopen Officiele Kamagra van Nederland

  4. Kennethslity表示:

    http://generic100mgeasy.com/# Generic100mgEasy

  5. TerryDus表示:

    http://generic100mgeasy.com/# cheapest viagra

  6. TerryDus表示:

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

  7. Kennethslity表示:

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

  8. WilliamNop表示:

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

  9. GregoryJough表示:

    kamagra 100mg kopen: kamagra pillen kopen – Kamagra Kopen

  10. WilliamNop表示:

    kamagra jelly kopen: Kamagra – kamagra kopen nederland

  11. Kennethslity表示:

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

  12. Dwayneseisa表示:

    KamagraKopen.pro KamagraKopen.pro kamagra pillen kopen

  13. GregoryJough表示:

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

  14. Kennethslity表示:

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

  15. LUCKY COLA表示:

    Top strategies for winning every game Lucky Cola

  16. Kennethslity表示:

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

  17. GregoryJough表示:

    kamagra 100mg kopen: KamagraKopen.pro – kamagra 100mg kopen

  18. WilliamNop表示:

    KamagraKopen.pro: Kamagra Kopen – KamagraKopen.pro

  19. Dwayneseisa表示:

    Generic100mgEasy buy generic 100mg viagra online sildenafil 50 mg price

  20. WilliamNop表示:

    Kamagra Kopen Online: kamagra jelly kopen – kamagra gel kopen

  21. TerryDus表示:

    http://tadalafileasybuy.com/# Cialis without a doctor prescription

  22. TerryDus表示:

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

  23. Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
    Мы предлагаем:ремонт крупногабаритной техники в москве
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  24. Dwayneseisa表示:

    buy generic 100mg viagra online Generic100mgEasy buy generic 100mg viagra online

  25. GregoryJough表示:

    Cheap Viagra 100mg: Generic 100mg Easy – Generic 100mg Easy

  26. EverettMibra表示:

    купить медицинские анализы клинический анализ купить

  27. Kennethslity表示:

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

  28. GregoryJough表示:

    kamagra gel kopen: Kamagra – KamagraKopen.pro

  29. WilliamNop表示:

    Tadalafil Easy Buy: TadalafilEasyBuy.com – Tadalafil Tablet

  30. WilliamNop表示:

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

發佈留言

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