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

  1. JohnniePaits表示:

    http://sildenafiliq.xyz/# Cheap Sildenafil 100mg

  2. RobertaRous表示:

    https://tadalafiliq.com/# Tadalafil Tablet

  3. DanielElorp表示:

    buy Kamagra Kamagra gel buy kamagra online usa

  4. Isaacwem表示:

    Kamagra tablets: Kamagra gel – buy kamagra online usa

  5. DanielElorp表示:

    Buy Cialis online tadalafil iq Generic Cialis without a doctor prescription

  6. RobertaRous表示:

    https://sildenafiliq.xyz/# sildenafil over the counter

  7. ChesterAsynC表示:

    sildenafil oral jelly 100mg kamagra: Sildenafil Oral Jelly – Kamagra Oral Jelly

  8. ChesterAsynC表示:

    viagra without prescription: Order Viagra 50 mg online – Viagra Tablet price

  9. RalphRem表示:

    http://kamagraiq.shop/# buy Kamagra

  10. Isaacwem表示:

    buy kamagra online usa: Kamagra Oral Jelly Price – sildenafil oral jelly 100mg kamagra

  11. ChesterAsynC表示:

    Cheap Sildenafil 100mg: best price on viagra – Viagra online price

  12. DanielElorp表示:

    Kamagra 100mg price Kamagra Iq super kamagra

  13. RalphRem表示:

    https://sildenafiliq.com/# buy Viagra online

  14. AA List表示:

    Good day! Do you know if they make any plugins to assist with SEO?
    I’m trying to get my blog to rank for some targeted keywords but I’m not
    seeing very good success. If you know of any please share.

    Thank you! I saw similar text here: Scrapebox AA List

  15. DanielElorp表示:

    sildenafil oral jelly 100mg kamagra Kamagra Oral Jelly Price п»їkamagra

  16. DanielElorp表示:

    Cialis without a doctor prescription cheapest cialis Generic Tadalafil 20mg price

  17. Isaacwem表示:

    Kamagra 100mg: Kamagra Iq – Kamagra 100mg price

  18. JohnniePaits表示:

    https://kamagraiq.com/# Kamagra tablets

  19. DanielElorp表示:

    Viagra online price cheapest viagra viagra without prescription

  20. Isaacwem表示:

    sildenafil over the counter: buy viagra online – buy Viagra over the counter

  21. DanielElorp表示:

    п»їkamagra Kamagra gel Kamagra 100mg price

  22. DanielElorp表示:

    Viagra tablet online over the counter sildenafil viagra without prescription

  23. RalphRem表示:

    https://kamagraiq.com/# Kamagra 100mg price

  24. Isaacwem表示:

    Viagra online price: Viagra tablet online – buy Viagra over the counter

  25. ChesterAsynC表示:

    Kamagra 100mg: Kamagra Oral Jelly Price – sildenafil oral jelly 100mg kamagra

  26. JohnniePaits表示:

    https://sildenafiliq.xyz/# generic sildenafil

  27. DanielElorp表示:

    Kamagra 100mg price kamagra best price Kamagra Oral Jelly

  28. RalphRem表示:

    http://tadalafiliq.com/# Generic Cialis price

  29. DanielElorp表示:

    Generic Tadalafil 20mg price Generic Tadalafil 20mg price Tadalafil price

  30. ChesterAsynC表示:

    Viagra without a doctor prescription Canada: buy viagra online – cheapest viagra

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

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