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

  1. Montebeera表示:

    reputable canadian pharmacy fda approved canadian online pharmacies canadian world pharmacy

  2. Georgewhend表示:

    india pharmacy without prescription: cheapest online pharmacy india – online medicine shopping in india

  3. Georgewhend表示:

    cheapest online pharmacy india: buying prescription drugs from india – IndiaMedFast

  4. JamesGag表示:

    canada pharmacy online: most reliable canadian online pharmacies – canada rx pharmacy

  5. Arthurhow表示:

    https://indiamedfast.com/# online medicine shopping in india
    northwest pharmacy canada

  6. Montebeera表示:

    legit canadian pharmacy most reliable canadian online pharmacies canadian pharmacy service

  7. JamesGag表示:

    lowest prescription prices online india: lowest prescription prices online india – india pharmacy without prescription

  8. Montebeera表示:

    canadian pharmacy service legitimate canadian pharmacies online trustworthy canadian pharmacy

  9. JamesGag表示:

    Mexican Pharm International: MexicanPharmInter – MexicanPharmInter

  10. Arthurhow表示:

    https://interpharmonline.shop/# canada drugs reviews
    trusted canadian pharmacy

  11. Arthurhow表示:

    https://mexicanpharminter.com/# buying from online mexican pharmacy
    best canadian pharmacy

  12. Georgewhend表示:

    certified canadian international pharmacy: Inter Pharm Online – best canadian pharmacy

  13. Georgewhend表示:

    IndiaMedFast: cheapest online pharmacy india – online medicine shopping in india

  14. JamesGag表示:

    my canadian pharmacy: Pharmacies in Canada that ship to the US – reliable canadian online pharmacy

  15. Montebeera表示:

    Mexican Pharm Inter Mexican Pharm Inter mexican pharmacy online order

  16. pdacenter.ru – сервис по ремонту бытовой техники
    Ремонт iPad в Чебоксарах в официальном сервисном центре PDACENTER.
    Наши инженеры выполняют ремонт любой сложности по дотупным ценам!

  17. JamesGag表示:

    cheapest online pharmacy india: india online pharmacy store – lowest prescription prices online india

  18. Montebeera表示:

    canadianpharmacymeds certified canada pharmacy online ed meds online canada

  19. Montebeera表示:

    reputable canadian pharmacy most trusted canadian pharmacies online canada drugs

  20. Williszew表示:

    http://mexicanpharminter.com/# mexican drug stores online

  21. Williszew表示:

    https://indiamedfast.shop/# order medicines online india

  22. Arthurhow表示:

    https://interpharmonline.com/# canadian pharmacy 365
    drugs from canada

  23. Williszew表示:

    https://mexicanpharminter.shop/# Mexican Pharm Inter

  24. Arthurhow表示:

    https://interpharmonline.shop/# canadian drug stores
    canada drugs online

  25. Arthurhow表示:

    http://indiamedfast.com/# india pharmacy without prescription
    canadian mail order pharmacy

  26. JamesGag表示:

    cheapest online pharmacy india: cheapest online pharmacy india – cheapest online pharmacy india

  27. Williszew表示:

    https://mexicanpharminter.com/# mexican drug stores online

  28. Arthurhow表示:

    https://interpharmonline.com/# canada pharmacy world
    canadian family pharmacy

  29. Josephsip表示:

    dang nh?p alo789: alo789 dang nh?p – alo 789

發佈留言

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