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

  1. Stevenkated表示:

    https://k8viet.guru/# nha cai k8

  2. Josephsip表示:

    k8 th? dam: link vao k8 – k8vip

  3. Josephsip表示:

    alo789in: alo 789 – alo 789 dang nh?p

  4. Stevenkated表示:

    https://alo789.auction/# alo789 chinh th?c

  5. Curtismence表示:

    https://88betviet.pro/# nha cai 88bet

  6. Rubengax表示:

    link vao k8 k8vip k8 bet

  7. Curtismence表示:

    https://88betviet.pro/# 88bet slot

  8. Josephsip表示:

    k8 th? dam: link vao k8 – nha cai k8

  9. Curtismence表示:

    https://alo789.auction/# alo789in

  10. Josephsip表示:

    k8 bet: k8 th? dam – k8

  11. Rubengax表示:

    88bet 88bet 188bet 88bet

  12. Stevenkated表示:

    https://88betviet.pro/# 188bet 88bet

  13. Rubengax表示:

    nha cai k8 k8 bet k8

  14. Josephsip表示:

    nha cai 88bet: 88bet slot – 88bet slot

  15. Rubengax表示:

    k8 bet k8 th? dam k8 bet

  16. Josephsip表示:

    alo789in: alo 789 dang nh?p – alo789 chinh th?c

  17. Stevenkated表示:

    http://88betviet.pro/# keo nha cai 88bet

  18. Josephsip表示:

    nha cai k8: nha cai k8 – k8

  19. Curtismence表示:

    https://k8viet.guru/# k8 th? dam

  20. Curtismence表示:

    http://k8viet.guru/# k8 bet

  21. Curtismence表示:

    https://88betviet.pro/# 88bet slot

  22. Curtismence表示:

    https://k8viet.guru/# k8 bet

  23. Josephsip表示:

    alo789in: alo 789 – alo789hk

  24. Josephsip表示:

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

  25. Stevenkated表示:

    http://alo789.auction/# alo789in

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

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