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

  1. Larrylab表示:

    medicine in mexico pharmacies mexican pharmacy buying from online mexican pharmacy

  2. Larrylab表示:

    pharmacy com canada Pharmacies in Canada that ship to the US best rated canadian pharmacy

  3. Roscoeevern表示:

    https://mexicanpharmgrx.com/# purple pharmacy mexico price list

  4. Larrylab表示:

    mexico pharmacy Pills from Mexican Pharmacy mexican pharmaceuticals online

  5. DavidJeado表示:

    canadian pharmacy online store: International Pharmacy delivery – certified canadian international pharmacy

  6. LamarSix表示:

    northwest canadian pharmacy: List of Canadian pharmacies – canadian pharmacy meds review

  7. Roscoeevern表示:

    http://canadianpharmgrx.xyz/# reliable canadian online pharmacy

  8. Larrylab表示:

    canadian pharmacy tampa Best Canadian online pharmacy legitimate canadian pharmacy online

  9. LamarSix表示:

    buy prescription drugs from india: indian pharmacy delivery – online shopping pharmacy india

  10. Roscoeevern表示:

    https://mexicanpharmgrx.com/# best mexican online pharmacies

  11. Larrylab表示:

    canadian pharmacy king My Canadian pharmacy canadian pharmacy

  12. Chasefounc表示:

    buying prescription drugs in mexico: Mexico drugstore – medication from mexico pharmacy

  13. DavidJeado表示:

    pharmacy website india: indian pharmacy delivery – online pharmacy india

  14. Larrylab表示:

    indian pharmacy online indian pharmacy delivery online pharmacy india

  15. Larrylab表示:

    canadian drug Canada pharmacy online canada pharmacy online

  16. DavidJeado表示:

    northwest canadian pharmacy: My Canadian pharmacy – cross border pharmacy canada

  17. Roscoeevern表示:

    https://canadianpharmgrx.xyz/# canadian pharmacy no rx needed

  18. Larrylab表示:

    india online pharmacy indian pharmacy delivery top online pharmacy india

  19. Larrylab表示:

    reputable canadian online pharmacies Certified Canadian pharmacies canadian pharmacy store

  20. Roscoeevern表示:

    http://mexicanpharmgrx.shop/# mexico pharmacies prescription drugs

  21. Chasefounc表示:

    buying prescription drugs in mexico: medicine in mexico pharmacies – mexican pharmacy

  22. LamarSix表示:

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

  23. Larrylab表示:

    indian pharmacy Generic Medicine India to USA pharmacy website india

  24. DavidJeado表示:

    mexican pharmaceuticals online: online pharmacy in Mexico – buying prescription drugs in mexico

  25. Larrylab表示:

    mexico pharmacy Mexico drugstore mexico pharmacies prescription drugs

  26. Roscoeevern表示:

    https://mexicanpharmgrx.com/# mexican pharmacy

  27. Larrylab表示:

    indian pharmacy Healthcare and medicines from India online shopping pharmacy india

  28. LamarSix表示:

    buying prescription drugs in mexico: mexican pharmacy – purple pharmacy mexico price list

  29. Larrylab表示:

    online canadian pharmacy review Canada pharmacy canadian pharmacy world reviews

  30. Roscoeevern表示:

    http://mexicanpharmgrx.shop/# mexican pharmaceuticals online

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

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