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

  1. TerryDus表示:

    http://generic100mgeasy.com/# buy viagra here

  2. TerryDus表示:

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

  3. Kennethslity表示:

    https://tadalafileasybuy.shop/# cialis without a doctor prescription

  4. Dwayneseisa表示:

    Kamagra kamagra kopen nederland Kamagra

  5. Kennethslity表示:

    http://tadalafileasybuy.com/# TadalafilEasyBuy.com

  6. GregoryJough表示:

    Kamagra Kopen: kamagra pillen kopen – KamagraKopen.pro

  7. Kennethslity表示:

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

  8. JamesGag表示:

    MexicanPharmInter: mexican pharmacy online store – reliable mexican pharmacies

  9. Howardenace表示:

    canadian pharmacy 24h com: most reliable canadian online pharmacies – canadian pharmacy 24 com

  10. Williszew表示:

    https://interpharmonline.shop/# canadian drug prices

  11. Williszew表示:

    https://mexicanpharminter.shop/# buying from online mexican pharmacy

  12. Montebeera表示:

    order medicines online india IndiaMedFast online medicine shopping in india

  13. Arthurhow表示:

    http://mexicanpharminter.com/# reliable mexican pharmacies
    canadian drugs online

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

  15. JamesGag表示:

    legit canadian pharmacy: InterPharmOnline.com – canada rx pharmacy

  16. Williszew表示:

    https://interpharmonline.shop/# canada pharmacy online

  17. Montebeera表示:

    cheapest online pharmacy india lowest prescription prices online india india pharmacy without prescription

  18. Howardenace表示:

    canadian pharmacy meds: fda approved canadian online pharmacies – safe online pharmacies in canada

  19. Williszew表示:

    http://indiamedfast.com/# IndiaMedFast.com

  20. JamesGag表示:

    order medicines online india: IndiaMedFast.com – online medicine shopping in india

  21. Howardenace表示:

    canadian pharmacy ltd: canada pharmacy no prescription – canadian world pharmacy

  22. JamesGag表示:

    Mexican Pharm International: MexicanPharmInter – Mexican Pharm Inter

  23. Williszew表示:

    https://interpharmonline.com/# safe canadian pharmacy

  24. Arthurhow表示:

    http://indiamedfast.com/# India Med Fast
    canadian pharmacy service

  25. JamesGag表示:

    reliable mexican pharmacies: MexicanPharmInter – mexican pharmacy online store

  26. Howardenace表示:

    canadian pharmacy 1 internet online drugstore: Cheapest online pharmacy – canada drugstore pharmacy rx

  27. Howardenace表示:

    best canadian online pharmacy: fda approved canadian online pharmacies – canadadrugpharmacy com

  28. Montebeera表示:

    77 canadian pharmacy legitimate canadian pharmacies online legit canadian pharmacy

  29. Williszew表示:

    https://indiamedfast.com/# buying prescription drugs from india

  30. Williszew表示:

    https://indiamedfast.shop/# India Med Fast

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

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