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

13,402 Responses

  1. Consolidate Debt Management With 0% Balance Transfers 다바오 다운

  2. Top Five 2004 Required Marketing Tips Needed Greatest And Fullest 에볼루션 알 판매

  3. 789 bet表示:

    That is a really good tip especially to those fresh to the blogosphere. Simple but very accurate information… Thank you for sharing this one. A must read post!

  4. How To Become More Unique Traffic With Article Writing
    Works . 구글상위노출 업체

  5. Car Finance Tips – A Strategies Car Loans 다바오 여자 대학교

  6. Happy Birthday Cards – Choosing Means To Achieve Card For The Birthday Person 소상공인 대출

  7. Good day! I could have sworn I’ve visited this site before but after looking at a few of the posts I realized it’s new to me. Nonetheless, I’m definitely happy I stumbled upon it and I’ll be bookmarking it and checking back frequently!

  8. A Few Of The Best Atlantic City Casinos 프라그마틱 환수율

  9. 78win表示:

    You should be a part of a contest for one of the greatest blogs online. I am going to recommend this web site!

  10. An impressive share! I have just forwarded this onto a colleague who has been doing a little research on this. And he in fact bought me lunch because I discovered it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending the time to discuss this subject here on your internet site.

  11. JamesBak表示:

    ciprofloxacin: antibiotics cipro – buy ciprofloxacin

  12. JamesBak表示:

    cost generic clomid without a prescription: where buy cheap clomid now – how to buy cheap clomid price

  13. 대출表示:

    Payday Loan – Exactly How It And The Way That It Works 대출

  14. Improve Your Search Engine Ranking – 4 Free Easy Ways To Get
    Backlinks 검색엔진최적화 전문가

  15. JamesBak表示:

    paxlovid covid: paxlovid for sale – buy paxlovid online

  16. Myra Goeing表示:

    An outstanding share! I have just forwarded this onto a coworker who was doing a little homework on this. And he actually bought me lunch due to the fact that I discovered it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanx for spending the time to discuss this topic here on your web site.

  17. JamesBak表示:

    can i purchase generic clomid without prescription: generic clomid – can i buy generic clomid without rx

  18. JamesBak表示:

    cost doxycycline tablets: doxycycline india – doxycycline hyc

  19. JamesBak表示:

    rx clomid: where can i buy generic clomid without dr prescription – cost of clomid for sale

  20. ThomasDet表示:

    http://paxloviddelivery.pro/# п»їpaxlovid

  21. ThomasDet表示:

    http://doxycyclinedelivery.pro/# buy doxycycline online australia

  22. JamesBak表示:

    doxycycline cost united states: doxyciclin – doxycycline 1mg

  23. JamesBak表示:

    cipro online no prescription in the usa: ciprofloxacin 500mg buy online – buy cipro cheap

  24. ThomasDet表示:

    http://doxycyclinedelivery.pro/# doxycycline 300 mg cost

  25. ThomasDet表示:

    http://ciprodelivery.pro/# buy generic ciprofloxacin

  26. I want to to thank you for this great read!! I certainly loved every bit of it. I have you book marked to check out new stuff you post…

  27. JamesBak表示:

    ciprofloxacin generic: where to buy cipro online – buy cipro online

  28. ThomasDet表示:

    https://amoxildelivery.pro/# amoxicillin 500 mg

發佈留言

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