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

9,758 Responses

  1. RobertSoish表示:

    where to buy amoxicillin 500mg without prescription: amoxicillin 500mg price – ampicillin amoxicillin

  2. RobertSoish表示:

    clomid sale: get cheap clomid without rx – buy cheap clomid without prescription

  3. JamesBak表示:

    can i order clomid pill: can i order generic clomid no prescription – get clomid without rx

  4. JamesBak表示:

    paxlovid pharmacy: paxlovid pill – paxlovid pill

  5. www.hrcu.tv表示:

    The Free Online Backlink Checker! I Know Where You
    Are Able To Find Person! seo 최적화 (http://www.hrcu.tv)

  6. Too Much Payday Loan And Minute Card Debt? Try Consolidation gg포커 다바오

  7. How To Develop A Search Engine Friendly Website 구글 백링크 (rbenorthwesteng.com)

發佈留言

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