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

26,694 Responses

  1. Michaelnot表示:

    http://claritin.icu/# ventolin 500 mcg

  2. sitemap.xml表示:

    It’s nearly impossible too find educated people about this topic, bbut you seemm lije
    yoou know what you’re talkkng about! Thanks

  3. sitemap.xml表示:

    Wonderful article! Thatt is the typ off info that arre meant tto bbe shared
    aroiund thhe internet. Shhame on the seek engines for not poositioning this subnit higher!
    Come on ovger aand vvisit myy weeb skte . Thajk you =)

  4. sitemap表示:

    If youu wannt tto ijprove your familiariyy simply keep visitung
    this webb sige and bbe updated wikth thhe most recent
    news update posted here.

  5. RobertRix表示:

    medications with no prescription: online pharmacy no prescription – canadian pharmaceutical ordering

  6. Richardves表示:

    reputable indian pharmacies: buy prescription drugs from india – top online pharmacy india

  7. JamesSpisk表示:

    https://buydrugsonline.top/# online ed medication no prescription

  8. RobertRix表示:

    northwest canadian pharmacy: buy prescription drugs online without doctor – canadian mail order viagra

  9. DanielDit表示:

    canada pharmacies online prescriptions Top mail order pharmacies canada drug online

  10. Richardves表示:

    online pharmacy india: mail order pharmacy india – indian pharmacy paypal

  11. JamesSpisk表示:

    http://buydrugsonline.top/# canadian pharmacy no prescription required

  12. RobertRix表示:

    best online pharmacy india: online shopping pharmacy india – best india pharmacy

  13. Richardves表示:

    canada drugs online review: safe online pharmacy – pharmacy in canada

  14. JamesSpisk表示:

    https://mexicopharmacy.store/# mexican drugstore online

  15. Charlesrhype表示:

    prinivil 20 mg tablet buy lisinopril online lisinopril generic 10 mg

  16. ScottJeove表示:

    buy zestril: prescription for lisinopril – lisinopril medicine

  17. JamesFliva表示:

    https://doxycycline.forum/# doxycycline 100mg canada

  18. VernonTratt表示:

    cipro ciprofloxacin: ciprofloxacin without insurance – cipro

  19. Charlesrhype表示:

    amoxicillin without a prescription amoxil for sale amoxicillin in india

  20. ScottJeove表示:

    buy doxycycline 100mg pills: Buy doxycycline hyclate – doxycycline 100 cost

  21. JamesFliva表示:

    https://azithromycin.bar/# zithromax for sale online

  22. ScottJeove表示:

    lisinopril tabs 20mg: buy lisinopril – zestril 20 mg tab

  23. Charlesrhype表示:

    antibiotics cipro antibiotics cipro antibiotics cipro

  24. VernonTratt表示:

    zithromax tablets for sale: buy zithromax – where can i buy zithromax capsules

  25. ScottJeove表示:

    doxycycline 1000mg: Buy Doxycycline for acne – doxycycline tablets buy online

  26. Charlesrhype表示:

    buy ciprofloxacin over the counter buy ciprofloxacin online buy cipro online without prescription

  27. JamesFliva表示:

    https://doxycycline.forum/# doxycycline 500mg capsules

  28. ScottJeove表示:

    where to get amoxicillin over the counter: amoxil for sale – can i buy amoxicillin online

  29. VernonTratt表示:

    zithromax prescription online: zithromax z-pak – buy zithromax 1000mg online

發佈留言

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