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

13,414 Responses

  1. This Is How Malpractice Case Will Look In 10 Years’ Time Malpractice lawsuit

  2. 7 Simple Secrets To Totally Rocking Your Door Repairs Near Me Upvc Windows Repairs Near Me

  3. unsplash.com表示:

    Greetings, comrade enthusiast. I must laud you on your discerning analysis of
    the subject matter presented in this blog post.

    Your piercing observations and eloquent commentary have resonated with me,
    and I ascertain myself in consensus with the convictions you have
    communicated .

    Given your apparent fascination in the realm of
    cyber finance, I would be neglectful if I did not provide an invitation for you to discover the enthralling
    world of Crypto Casino. This revolutionary
    platform offers a uncommon and immersive escapade , blending the fervor of conventional casino gaming with
    the revolutionary systems of distributed ledger
    . I consider you would uncover it a most compelling
    foray. I urge you to be a part of us and uncover the
    inexhaustible opportunities that await you.

    my web site: online casino loyalty programs, unsplash.com,

  4. 20 Myths About Repairing Upvc Windows: Busted Upvc Window repair

  5. The No. 1 Question Everyone Working In Upvc Windows And Doors Should Be Able To Answer
    Repair Upvc Window

  6. Best Seo Keyword Research Technique To Dominate The Search Engine 구글상위노출 대행사

  7. double Door表示:

    The Complete Guide To Double Glazed Doors Near Me double Door

  8. Imogene表示:

    20 Malpractice Claim Websites Taking The Internet By Storm malpractice lawyer – Imogene

  9. Online Crash And Burn Marketing Vs The Slow And Steady Approach 에볼루션 추천

  10. How To Create Successful Double Glazed Window Repair Strategies From Home Window repairs near me; rodgers-fagan.mdwrite.net,

  11. Free Roll Online Poker Tournament Structure And Strategy 프라그마틱 게임

  12. Five Killer Quora Answers To Replacement Double Glazing Units Near Me replacement Double glazing units near me

  13. installation表示:

    11 Methods To Completely Defeat Your Double Glazing Near Me
    installation

  14. This is the right weblog for anybody who desires to find out about this topic. You realize a lot its almost arduous to argue with you (not that I really would want…HaHa). You positively put a new spin on a subject thats been written about for years. Great stuff, simply great!

  15. Katrin表示:

    The People Nearest To Upvc Window Repairs Tell You Some Big Secrets upvc windows
    doors; Katrin,

  16. Card Maker – How Well Does Charge Card Software
    Do The Job? 저신용자 대출

  17. Aw, it was a really good post. In concept I must invest writing this way moreover – taking time and actual effort to manufacture a top notch article… but what can I say… I procrastinate alot and by no indicates appear to get something carried out.

  18. Why You Should Concentrate On Enhancing Double Glazed Window Replacement Windowpane Replacement

  19. Youre so cool! I dont suppose Ive read anything in this way before. So nice to discover somebody with a few original thoughts on this subject. realy appreciation for beginning this up. this web site is something that is required over the internet, a person with a little originality. useful job for bringing something new to the web!

  20. 10 Situations When You’ll Need To Be Educated About Repair Timber Windows Double Glazed
    Window Repairs Near Me (http://Velo-Xachmas.Com/)

  21. Hey there just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different internet browsers and both show the same outcome.

  22. earwigs表示:

    find dining might be expensive but the menu and service is always the best`

  23. repaired表示:

    11 “Faux Pas” Which Are Actually OK To Do With Your Repair Upvc
    Windows repaired

  24. Can you please email me the info on how you designed your homepage? Did you do that with a template or is it custom? I stink at this stuff, but it looks great!

  25. Five Killer Quora Answers To Slot Demo Gatot Kaca Puri slot demo gatot Kaca puri, morphomics.science,

  26. 10 Locations Where You Can Find Kids Bunk Bed With Stairs
    kids bunk beds

  27. 5 Things That Everyone Is Misinformed About Regarding Medical
    Malpractice Legal Medical Malpractice Attorney

  28. 20 Fun Facts About SEO Tool Vps Seo Software Rankings

  29. 10 Facts About Upvc Window Repairs That Can Instantly
    Put You In Good Mood Upvc window repairs near me

  30. This blog was… how do I say it? Relevant!! Finally I’ve found something that helped me. Kudos.

發佈留言

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