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

25,130 Responses

  1. I’ve been absent for a while, but now I remember why I used to love this website. Thanks , I will try and check back more frequently. How frequently you update your website?

  2. Josephsip表示:

    88 bet: keo nha cai 88bet – 188bet 88bet

  3. Curtismence表示:

    http://k8viet.guru/# k8 bet

  4. Artificial sweeteners are chemically designed to faux out your style buds and your digestive system..

  5. Josephsip表示:

    nha cai k8: k8vip – k8vip

  6. Curtismence表示:

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

  7. Rubengax表示:

    alo789 chinh th?c alo 789 alo789 chinh th?c

  8. Josephsip表示:

    k8: nha cai k8 – k8 bet

  9. Stevenkated表示:

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

  10. For minority languages, you probably do not get a duolingo app, or a bar or hotel staff using it.

  11. Josephsip表示:

    alo789hk: alo789in – alo789 dang nh?p

  12. Stevenkated表示:

    http://alo789.auction/# alo789hk

  13. CAP would like to extend its thanks to the various trade our bodies, farming organisations and authorities officials who supplied invaluable info and insight into regenerative farming in the UK for the purposes of this text.

  14. Listing of employment information for registered people together with detailed agency information and termination motive.

  15. BernardFax表示:

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

  16. Rubengax表示:

    k8 th? dam k8 bet link vao k8

  17. Rubengax表示:

    k8 k8 bet k8vip

  18. Curtismence表示:

    https://alo789.auction/# alo789in

  19. Josephsip表示:

    alo789: alo789hk – 789alo

  20. Curtismence表示:

    http://alo789.auction/# alo 789 dang nh?p

  21. MatthewQuish表示:

    водительское медицинская справка спб медицинская справка для водительских прав спб

  22. Josephsip表示:

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

  23. BernardFax表示:

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

發佈留言

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