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

  1. Jeromedug表示:

    buy cytotec over the counter buy cytotec online fast delivery buy cytotec over the counter

  2. ArchieAnice表示:

    https://misoprostol.top/# buy cytotec over the counter

  3. Jamesempiz表示:

    buy cipro online without prescription: ciprofloxacin 500 mg tablet price – ciprofloxacin 500mg buy online

  4. RussellVog表示:

    how to buy doxycycline online: where to get doxycycline – buy generic doxycycline

  5. Jeromedug表示:

    ciprofloxacin order online cipro cipro 500mg best prices

  6. ArchieAnice表示:

    https://misoprostol.top/# buy cytotec over the counter

  7. Larrylab表示:

    canadian neighbor pharmacy CIPA approved pharmacies canadian pharmacy king

  8. Roscoeevern表示:

    http://indianpharmgrx.com/# cheapest online pharmacy india

  9. Chasefounc表示:

    п»їlegitimate online pharmacies india: indian pharmacy delivery – Online medicine home delivery

  10. Larrylab表示:

    thecanadianpharmacy My Canadian pharmacy medication canadian pharmacy

  11. Larrylab表示:

    top online pharmacy india indian pharmacy delivery best online pharmacy india

  12. Roscoeevern表示:

    http://canadianpharmgrx.com/# canadian pharmacy world

  13. Larrylab表示:

    canadian drugstore online Certified Canadian pharmacies canada pharmacy online

  14. DavidJeado表示:

    top online pharmacy india: Generic Medicine India to USA – indian pharmacies safe

  15. Larrylab表示:

    top 10 online pharmacy in india indian pharmacy delivery world pharmacy india

  16. LamarSix表示:

    reputable indian pharmacies: п»їlegitimate online pharmacies india – online pharmacy india

  17. Larrylab表示:

    mexico drug stores pharmacies online pharmacy in Mexico mexican drugstore online

  18. LamarSix表示:

    indian pharmacy online: Healthcare and medicines from India – best online pharmacy india

  19. Chasefounc表示:

    best india pharmacy: Online medicine home delivery – pharmacy website india

  20. Roscoeevern表示:

    http://canadianpharmgrx.xyz/# canada pharmacy reviews

  21. LamarSix表示:

    best online pharmacy india: indian pharmacy delivery – indian pharmacies safe

  22. DavidJeado表示:

    online pharmacy india: Generic Medicine India to USA – india pharmacy

  23. Larrylab表示:

    canadian pharmacy Canada pharmacy canadapharmacyonline legit

  24. Larrylab表示:

    mexican pharmacy Mexico drugstore best online pharmacies in mexico

  25. DavidJeado表示:

    reputable canadian pharmacy: CIPA approved pharmacies – canadianpharmacyworld

  26. Roscoeevern表示:

    http://mexicanpharmgrx.shop/# medication from mexico pharmacy

  27. Larrylab表示:

    cheapest online pharmacy india indian pharmacy delivery indianpharmacy com

  28. Roscoeevern表示:

    http://indianpharmgrx.shop/# top online pharmacy india

  29. Larrylab表示:

    my canadian pharmacy reviews CIPA approved pharmacies real canadian pharmacy

  30. Chasefounc表示:

    Online medicine order: indian pharmacy – india pharmacy mail order

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

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