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

  1. DanielTet表示:

    buy cytotec https://tamoxifen.bid/# nolvadex generic
    furosemide 100mg

  2. DanielTet表示:

    buy cytotec https://lisinopril.guru/# lisinopril best price
    lasix 100 mg tablet

  3. Stephenzek表示:

    http://lipitor.guru/# lipitor generic atorvastatin

  4. Marian表示:

    Ten Situations In Which You’ll Want To Know About Adhd Adults Assessment adhd assessment for
    adults edinburgh (Marian)

  5. Abel表示:

    my blog post: Explore Daycares Locations (Abel)

  6. The No. 1 Question Everybody Working In Door Fitters Milton Keynes Must Know
    How To Answer Milton Keynes Locksmith

  7. Jamesric表示:

    lasix 40mg: lasix dosage – lasix 100 mg tablet

  8. Stanleyinolf表示:

    buy cytotec over the counter buy cytotec pills cytotec pills buy online

  9. Stanleyinolf表示:

    nolvadex half life Purchase Nolvadex Online tamoxifen alternatives

  10. Jamesric表示:

    buy lisinopril 5 mg: Lisinopril refill online – lisinopril 5 mg prices

  11. Jamesric表示:

    buy cytotec online fast delivery: buy misoprostol tablet – Misoprostol 200 mg buy online

  12. Stephenzek表示:

    http://furosemide.win/# furosemide 100 mg

  13. Good post. I learn something new and challenging on blogs I stumbleupon on a daily basis. It’s always exciting to read content from other authors and practice a little something from their web sites.

  14. Also visit my blog post – Comicsformoms.Com

  15. Jamesric表示:

    buy furosemide online: cheap lasix – lasix furosemide

  16. 果て 類語表示:

    It also seamlessly integrates with Microsoft Exchange Server.

  17. Stephenzek表示:

    http://lisinopril.guru/# zestoretic

  18. They could use it at home, school, or work.

  19. Stephenzek表示:

    https://tamoxifen.bid/# nolvadex d

  20. Improving the user experience and providing educational resources are crucial for broader adoption of DEX platforms.

  21. Jamesric表示:

    lasix 40 mg: cheap lasix – lasix 40 mg

  22. DanielTet表示:

    buy cytotec pills https://tamoxifen.bid/# tamoxifen premenopausal
    lasix medication

  23. There are vendors like ‘Tatenda’ selling South African inspired clothes and crafts, Owen’s Angus Jams for their speciality in Jams and gins, K9 Health Centre for dog food buffet, and some finest honey from Rose Valley.

  24. Jamesric表示:

    lasix tablet: cheap lasix – furosemide 100 mg

  25. For anyone who use Mac, you will need to obtain a separate Forex trading software for Mac, or alternatively get a version that is compatible.

  26. DanielTet表示:

    buy cytotec over the counter https://lipitor.guru/# lipitor 40 mg price
    lasix 40mg

  27. Jamesric表示:

    buy furosemide online: furosemide online – lasix 100 mg tablet

  28. DanielTet表示:

    buy cytotec online http://furosemide.win/# furosemide 40 mg
    lasix 100 mg

  29. Stephenzek表示:

    https://tamoxifen.bid/# п»їdcis tamoxifen

發佈留言

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