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

  1. Poker Could Be The Ultimate Card Game 다바오 커플 호텔

  2. seo 백링크表示:

    Organic Search Engine Marketing Tactics For Online
    Programs seo 백링크

  3. Search Engine Optimization – From Zero To Hero 검색엔진최적화 사례

  4. When I initially left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get 4 emails with the exact same comment. Is there a way you are able to remove me from that service? Kudos.

  5. Keyword Research For Seo 백링크 확인 (http://forretailers.com)

  6. The Top Casino Gambling Games 에볼루션 코리아 (http://imagesecure.com/)

  7. miami psychic表示:

    Aw, this was a really nice post. Taking the time and actual effort to generate a really good article… but what can I say… I put things off a whole lot and never seem to get anything done.

  8. How Decide On A Best Seo Company 백링크 확인 (gregoryromine.com)

  9. I used to be able to find good info from your blog articles.

  10. seo 최적화表示:

    How To Rank Higher On Search Engines By Getting High Page Rank seo 최적화

發佈留言

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