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

26,722 Responses

  1. JasonWal表示:

    prednisone prescription online: prednisone 20mg prices – can you buy prednisone without a prescription

  2. JasonWal表示:

    buy amoxicillin from canada: amoxicillin 500mg capsules – can you buy amoxicillin over the counter

  3. Hermanges表示:

    amoxicillin 500 mg where to buy amoxicillin amoxicillin 500mg capsule buy online

  4. JasonWal表示:

    ciprofloxacin order online: ciprofloxacin mail online – buy cipro cheap

  5. JasonWal表示:

    paxlovid generic: paxlovid for sale – paxlovid pharmacy

  6. JasonWal表示:

    cost of amoxicillin prescription: amoxicillin 500mg prescription – how to buy amoxicillin online

  7. Raymondsmero表示:

    http://paxlovid.win/# п»їpaxlovid

  8. JasonWal表示:

    can i buy prednisone online without prescription: can you buy prednisone without a prescription – 30mg prednisone

  9. JasonWal表示:

    where to buy amoxicillin pharmacy: amoxil pharmacy – azithromycin amoxicillin

  10. BrianDutle表示:

    https://prednisone.bid/# prednisone online pharmacy

  11. Hermanges表示:

    cipro ciprofloxacin buy cipro cheap cipro for sale

  12. JasonWal表示:

    paxlovid for sale: buy paxlovid online – paxlovid

  13. JasonWal表示:

    how much is prednisone 5mg: prednisone 20mg price in india – prednisone 4mg

  14. JasonWal表示:

    where can i get cheap clomid pills: where to buy generic clomid prices – can i order generic clomid now

  15. Raymondsmero表示:

    https://paxlovid.win/# buy paxlovid online

  16. JasonWal表示:

    buy paxlovid online: paxlovid – paxlovid price

  17. Hermanges表示:

    cost of generic clomid price where buy cheap clomid without prescription how to get cheap clomid prices

  18. JasonWal表示:

    paxlovid price: Paxlovid over the counter – paxlovid buy

  19. This Site表示:

    Hmm is anyone else experiencing problems with the images on this
    blog loading? I’m trying to figure out if its a problem on my end or if
    it’s the blog. Any responses would be greatly appreciated.

  20. RalphBic表示:

    http://edpills.tech/# best treatment for ed edpills.tech

  21. RalphBic表示:

    https://edpills.tech/# buy ed pills edpills.tech

  22. Wilfredtar表示:

    cheapest online pharmacy india india pharmacy – indian pharmacies safe indiapharmacy.guru

  23. Joshuafab表示:

    https://indiapharmacy.pro/# indianpharmacy com indiapharmacy.pro

  24. RalphBic表示:

    http://edpills.tech/# best over the counter ed pills edpills.tech

  25. RalphBic表示:

    http://edpills.tech/# buy ed pills edpills.tech

  26. DavidFUs表示:

    buy medicines online in india п»їlegitimate online pharmacies india – india pharmacy indiapharmacy.guru

  27. JeffreyAmush表示:

    Online medicine order reputable indian online pharmacy reputable indian online pharmacy indiapharmacy.guru

  28. RalphBic表示:

    https://edpills.tech/# medicine for impotence edpills.tech

  29. RalphBic表示:

    http://canadiandrugs.tech/# online canadian pharmacy review canadiandrugs.tech

  30. RalphBic表示:

    https://edpills.tech/# erectile dysfunction medicines edpills.tech

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

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