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

  1. Pretty! This has been an extremely wonderful article. Many thanks for providing this info.

  2. Louann表示:

    The Largest Issue That Comes With Modern Leather Sofa, And How You Can Fix It tufted leather sofa (Louann)

  3. LarryCoell表示:

    az parayla cok kazandiran slot oyunlar? az parayla cok kazandiran slot oyunlar? slot siteleri

  4. ClydePab表示:

    az parayla cok kazandiran slot oyunlar?: slot tr online – slot oyunlar?

  5. Derekfar表示:

    matadorbet bid: matadorbet – matadorbet.bid

  6. LarryCoell表示:

    deneme bonusu veren siteler betturkey betturkey.com denemebonusuverensiteler.top deneme bonusu veren siteler yerliarama.org

  7. ClydePab表示:

    ultrabet tr online: ultrabet tr online – ultrabet guncel

  8. HassanbuifS表示:

    http://denemebonusuverensiteler.top/# deneme bonusu veren siteler yeni
    deneme bonusu veren siteler yerliarama.org

  9. Derekfar表示:

    matadorbet giris: matadorbet.bid – matadorbet bid

  10. LarryCoell表示:

    ultrabet guncel ultrabet yeni giris 1125 ultrabet giris

  11. Brook表示:

    The 3 Biggest Disasters In Asbestos Injury Attorney History mesothelioma lawyers (Brook)

  12. CarrollUnton表示:

    deneme bonusu veren yeni siteler https://slot-tr.online/# slot tr online

  13. ClydePab表示:

    ultrabet: ultrabet guncel – ultrabet

  14. 10 Things That Your Family Taught You About Treadmills With Incline For Sale Treadmills With Incline For Sale (Palangshim.Com)

  15. The 10 Most Terrifying Things About Cheap Sofas For Sale sofas For Sale

  16. Derekfar表示:

    deneme bonusu veren yeni siteler: deneme bonusu veren siteler mycbet.com – deneme bonusu veren siteler denemebonusu2026.com

  17. 11 Ways To Completely Redesign Your Fabric Corner Sofa
    Cheap 2 Seater Fabric Sofa

  18. Тут можно преобрести несгораемый сейф цена огнестойкие сейфы

  19. Тут можно преобрести несгораемый сейф огнестойкий сейф купить

  20. LarryCoell表示:

    slot siteleri slot oyunlar? puf noktalar? en kazancl? slot oyunlar?

  21. HassanbuifS表示:

    http://matadorbet.bid/# matadorbet.bid
    deneme bonusu veren siteler mycbet.com

  22. Derekfar表示:

    matadorbet.bid: matadorbet.bid – matadorbet.bid

  23. LarryCoell表示:

    Canl? Casino Siteleri Casino Siteleri guvenilir casino siteleri

  24. How To Become A Prosperous Attorneys Accidents Entrepreneur Even If You’re Not Business-Savvy accident
    injury law firm (https://Posteezy.Com)

  25. Why You’ll Want To Learn More About SEO Marketing Agency Professional Seo Agency

  26. HassanbuifS表示:

    http://ultrabet-tr.online/# ultrabet yeni giris 1125
    deneme bonusu veren siteler betturkey betturkey.com

  27. Guide To Commercial Gas Patio Heaters: The Intermediate Guide
    The Steps To Commercial Gas Patio Heaters commercial gas Patio heaters, https://www.bitsdujour.com/profiles/EV0Fow,

  28. LarryCoell表示:

    deneme bonusu veren siteler mycbet.com deneme bonusu veren siteler mycbet.com deneme bonusu veren siteler betturkey betturkey.com

發佈留言

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