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...

6,626 Responses

  1. Austinnet表示:

    cheapest online ed treatment: п»їed pills online – online prescription for ed

  2. Jameswaw表示:

    ivermectin 4 tablets price ivermectin 400 mg stromectol pill for humans

  3. Michaelhig表示:

    amoxicillin 800 mg price: amoxicillin 50 mg tablets – amoxicillin without a doctors prescription

  4. Jameswaw表示:

    can you buy zithromax over the counter in mexico can you buy zithromax online buy cheap generic zithromax

  5. JosephBix表示:

    https://prednisonea.store/# prednisone 5mg daily

  6. BrainDer表示:

    https://clomida.pro/# cheap clomid without a prescription

  7. Jameswaw表示:

    buy amoxicillin from canada how to buy amoxicillin online amoxicillin medicine over the counter

  8. BrainDer表示:

    https://prednisonea.store/# prednisone 475

  9. Michaelhig表示:

    how to buy prednisone online: prednisone tablet 100 mg – prednisone buy no prescription

  10. BryanAgist表示:

    medicine prednisone 10mg: buy prednisone 10mg online – prednisone 10 tablet

  11. BrainDer表示:

    http://amoxicillina.top/# amoxicillin for sale online

  12. Michaelhig表示:

    cost of clomid without dr prescription: where to buy clomid online – where buy clomid without dr prescription

  13. DomenicEcoff表示:

    amoxicillin 1000 mg capsule: amoxicillin 500mg buy online canada – order amoxicillin online no prescription

  14. Jameswaw表示:

    amoxicillin 500 capsule order amoxicillin online buy amoxicillin online with paypal

  15. BrainDer表示:

    https://prednisonea.store/# order prednisone online no prescription

  16. Jameswaw表示:

    where to buy amoxicillin amoxicillin 500 mg cost antibiotic amoxicillin

  17. DomenicEcoff表示:

    prednisone daily: prednisone tablets – can you buy prednisone in canada

  18. Michaelhig表示:

    prednisone 20mg online pharmacy: prednisone prices – 50mg prednisone tablet

  19. BrainDer表示:

    https://prednisonea.store/# prednisone for sale no prescription

  20. Jameswaw表示:

    amoxicillin 30 capsules price amoxicillin where to get medicine amoxicillin 500mg

  21. DomenicEcoff表示:

    amoxicillin pills 500 mg: amoxicillin 200 mg tablet – 875 mg amoxicillin cost

  22. JosephBix表示:

    https://azithromycina.pro/# zithromax 250 mg australia

  23. Jameswaw表示:

    zithromax online usa zithromax price canada zithromax cost australia

  24. BrainDer表示:

    http://azithromycina.pro/# zithromax for sale usa

  25. Jameswaw表示:

    zithromax price canada zithromax capsules australia zithromax drug

  26. Michaelhig表示:

    where buy clomid online: where can i get generic clomid now – order generic clomid online

發佈留言

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