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

15,133 Responses

  1. Jamesric表示:

    lipitor 40: Atorvastatin 20 mg buy online – buy generic lipitor online

  2. Jamesric表示:

    common side effects of tamoxifen: Purchase Nolvadex Online – nolvadex 10mg

  3. 10 Untrue Answers To Common Fold Away Treadmill Questions Do You Know The Correct Answers?

    Treadmills Fold Up

  4. Stephenzek表示:

    http://tamoxifen.bid/# tamoxifen lawsuit

  5. DanielTet表示:

    buy cytotec pills http://cytotec.pro/# п»їcytotec pills online
    lasix 20 mg

  6. DanielTet表示:

    buy cytotec online http://tamoxifen.bid/# tamoxifenworld
    buy furosemide online

  7. There Is No Doubt That You Require G Spot Vibrater G Spot Vibrators

  8. How To Explain Upvc Window Repairs To Your Grandparents Upvc
    window repairs near me – https://cornpoland94.werite.net

  9. There is definately a great deal to know about this subject. I really like all of the points you have made.

  10. PokerTube表示:

    Feel free to visit my web blog PokerTube

  11. Zoe表示:

    10 Things We Love About Electric Fire Place Suite black electric
    fire suite (Zoe)

  12. Hello, I do believe your site could be having browser compatibility problems. When I take a look at your web site in Safari, it looks fine but when opening in Internet Explorer, it’s got some overlapping issues. I just wanted to give you a quick heads up! Besides that, excellent site.

  13. Why People Don’t Care About General Anxiety Symptoms anxiety treatment symptoms (https://clashofcryptos.trade/)

  14. eugosto.Pt表示:

    9 Things Your Parents Teach You About Leather Couch
    With Chaise leather couch with Chaise (eugosto.Pt)

  15. The 10 Scariest Things About Double Glazed Window Repairs
    Near Me window repairs near me

  16. You’ll Be Unable To Guess Double Glazed Windows Repair Near Me’s Secrets windows repair near me

  17. What’s The Current Job Market For Generalized Anxiety Disorder
    Gad Professionals Like? Generalized Anxiety Disorder

  18. Jacquie表示:

    The 10 Most Dismal Male Mastubators Errors Of
    All Time Could Have Been Prevented best auto masturbator – Jacquie,

  19. Your Worst Nightmare Concerning Replace Glass In Window Come
    To Life Front Door Glass Replacement

  20. DouglasGed表示:

    indian pharmacy online: Best Indian pharmacy – pharmacy website india

  21. DouglasGed表示:

    Online medicine order: Indian pharmacy international shipping – indian pharmacies safe

  22. 15 Reasons Why You Shouldn’t Ignore Pills To Treat Anxiety anxiety attack natural treatment

  23. Themed Slots表示:

    Why Jackpot Slots Isn’t As Easy As You Think Themed Slots

  24. DouglasGed表示:

    purple pharmacy mexico price list: Purple pharmacy online ordering – best online pharmacies in mexico

  25. This Is The History Of Nissan Micra Key Replacement In 10 Milestones replacement key for nissan juke

  26. DouglasGed表示:

    best online ed pills: ED meds online with insurance – online ed medication

發佈留言

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