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

19,080 Responses

  1. Brandonnot表示:

    online canadian pharmacy review: best online canadian pharmacy – canadian drugs

  2. Brandonnot表示:

    Best online Indian pharmacy: Indian pharmacy international shipping – buy prescription drugs from india

  3. CurtisBam表示:

    Online pharmacy: Indian pharmacy international shipping – Indian Cert Pharm

  4. Injury Lawyer表示:

    The Ultimate Glossary Of Terms About Childbirth Injury
    Law Injury Lawyer

  5. Carrolleruck表示:

    https://indiancertpharm.com/# indian pharmacy
    canadian pharmacy ltd

  6. AndreDib表示:

    trusted canadian pharmacy https://mexicaneasypharm.shop/# mexican pharmaceuticals online
    online pharmacy india

  7. LarryReupt表示:

    best mail order pharmacy canada Canadian Md Pharm recommended canadian pharmacies

  8. Carrolleruck表示:

    https://indiancertpharm.com/# Online medicine
    canadian online drugs

  9. One prominent example is the story surrounding the name for this style of architecture.

  10. When the receiving computer lastly gets the packets (which may have all taken utterly completely different paths to get there), it makes use of directions contained inside the packets to reassemble the data into its authentic state.

  11. Wallacefex表示:

    slot oyunlar?: slot oyunlar? – en cok kazand?ran slot oyunlar?

  12. Wallacefex表示:

    sweet bonanza guncel: sweet bonanza yorumlar – sweet bonanza yorumlar

  13. BradleyEdino表示:

    slot oyunlar? puf noktalar? guvenilir slot siteleri slot oyunlar? puf noktalar?

  14. Wallacefex表示:

    denemebonusuverensiteler25: deneme bonusu veren yeni siteler – deneme bonusu veren yeni siteler

  15. Wallacefex表示:

    sweet bonanza slot: sweet bonanza oyna – sweet bonanza giris

  16. BradleyEdino表示:

    Casino Siteleri guvenilir casino siteleri casino bahis siteleri

  17. JasonUnsoG表示:

    https://denemebonusuverensiteler25.com/# deneme bonusu veren siteler

  18. Ismaelfer表示:

    Hello to every one, it’s truly a good for me to visit this website, it includes useful Information.

    https://artflo.com.ua/vybraty-ta-kupyty-linzi-v-fary-porady-ta-rekomendatsiyi

  19. JasonUnsoG表示:

    https://sweetbonanza25.com/# sweet bonanza slot

  20. JasonUnsoG表示:

    http://sweetbonanza25.com/# sweet bonanza kazanma saatleri

  21. 4-In-1 Bedside Crib Tools To Help You Manage Your Daily Life 4-In-1 Bedside
    Crib Trick That Every Person Should Know 4-In-1 Bedside Crib

  22. The 10 Worst Asbestos Attorney Mesothelioma Mistakes Of All Time
    Could Have Been Prevented Mesothelioma Lawsuit

  23. BradleyEdino表示:

    deneme bonusu veren yeni siteler deneme bonusu veren yeni siteler deneme bonusu veren siteler

  24. FrankEmine表示:

    guvenilir slot siteleri: slot siteleri – slot oyunlar? puf noktalar?

  25. FrankEmine表示:

    yat?r?ms?z deneme bonusu veren siteler: denemebonusuverensiteler25 – yat?r?ms?z deneme bonusu veren siteler

發佈留言

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