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. Dwayneseisa表示:

    TadalafilEasyBuy.com Buy Tadalafil 20mg Buy Tadalafil 10mg

  2. WilliamNop表示:

    Generic100mgEasy: Generic 100mg Easy – Generic 100mg Easy

  3. WilliamNop表示:

    Generic100mgEasy: buy generic 100mg viagra online – Generic100mgEasy

  4. Kennethslity表示:

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

  5. GregoryJough表示:

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

  6. Dwayneseisa表示:

    Kamagra Kamagra Kopen Kamagra

  7. TerryDus表示:

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

  8. WilliamNop表示:

    Kamagra Kopen: kamagra kopen nederland – kamagra 100mg kopen

  9. GregoryJough表示:

    kamagra pillen kopen: kamagra kopen nederland – Kamagra Kopen

  10. Kennethslity表示:

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

  11. Dwayneseisa表示:

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

  12. GregoryJough表示:

    Kamagra Kopen Online: kamagra pillen kopen – kamagra kopen nederland

  13. TerryDus表示:

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

  14. TerryDus表示:

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

  15. Kennethslity表示:

    http://generic100mgeasy.com/# Generic100mgEasy

  16. WilliamNop表示:

    Kamagra Kopen Online: Kamagra Kopen Online – kamagra jelly kopen

  17. GregoryJough表示:

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

  18. WilliamNop表示:

    Kamagra Kopen Online: kamagra 100mg kopen – kamagra kopen nederland

  19. Kennethslity表示:

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

  20. Dwayneseisa表示:

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

  21. Kennethslity表示:

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

  22. Kennethslity表示:

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

  23. GregoryJough表示:

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

  24. GregoryJough表示:

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

  25. The most severe complications from atrial fibrillation can occur when blood clots form in the heart, break apart, and travel to different components of the physique.

  26. Dwayneseisa表示:

    Generic 100mg Easy Generic 100mg Easy sildenafil over the counter

  27. WilliamNop表示:

    Officiele Kamagra van Nederland: KamagraKopen.pro – kamagra gel kopen

  28. WilliamNop表示:

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

  29. TerryDus表示:

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

發佈留言

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