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

11,812 Responses

  1. Nelsonbluck表示:

    buying prescription drugs in mexico online: mexico pharmacies prescription drugs – pharmacies in mexico that ship to usa

  2. DominicJaw表示:

    buying prescription drugs in mexico: mexican border pharmacies shipping to usa – buying from online mexican pharmacy

  3. Nelsonbluck表示:

    mexican rx online: best online pharmacies in mexico – reputable mexican pharmacies online

  4. DominicJaw表示:

    mexico drug stores pharmacies: mexican rx online – mexico drug stores pharmacies

  5. 10 Rng Slots Tricks Experts Recommend exciting slots, https://links.gtanet.com.br,

  6. Arnoldten表示:

    mexican online pharmacies prescription drugs mexico pharmacies prescription drugs pharmacies in mexico that ship to usa

  7. WayneCoirl表示:

    medicine in mexico pharmacies: mexico drug stores pharmacies – buying prescription drugs in mexico

  8. Porter表示:

    Review my web-site: Daycare Near Me By State – Porter

  9. DominicJaw表示:

    mexico drug stores pharmacies: best online pharmacies in mexico – п»їbest mexican online pharmacies

  10. Nelsonbluck表示:

    reputable mexican pharmacies online: buying from online mexican pharmacy – mexican rx online

  11. 10 Top Facebook Pages Of All-Time About Repair
    Glass Glass panel repair

  12. WayneCoirl表示:

    reputable mexican pharmacies online: mexican border pharmacies shipping to usa – mexico drug stores pharmacies

  13. Wisdom On Bunk Beds For Kids From An Older Five-Year-Old kids l shaped bunk beds

  14. WayneCoirl表示:

    mexico pharmacies prescription drugs: mexico pharmacies prescription drugs – best online pharmacies in mexico

  15. DominicJaw表示:

    mexican rx online: best online pharmacies in mexico – mexican pharmaceuticals online

  16. DominicJaw表示:

    buying from online mexican pharmacy: reputable mexican pharmacies online – mexican pharmaceuticals online

  17. Nelsonbluck表示:

    medication from mexico pharmacy: mexican mail order pharmacies – medication from mexico pharmacy

  18. Nelsonbluck表示:

    mexican mail order pharmacies: mexican online pharmacies prescription drugs – mexican online pharmacies prescription drugs

  19. 20 Fun Facts About Single Handle Stroller http://Www.9324874.xyz

  20. Arnoldten表示:

    mexico drug stores pharmacies mexican drugstore online mexican pharmaceuticals online

  21. WayneCoirl表示:

    purple pharmacy mexico price list: mexican border pharmacies shipping to usa – reputable mexican pharmacies online

  22. See What Retro Under Counter Fridge Freezer Tricks The Celebs Are
    Using Retro Under Counter Fridge Freezer

  23. DominicJaw表示:

    reputable mexican pharmacies online: medicine in mexico pharmacies – pharmacies in mexico that ship to usa

  24. Dev Patel showed his great acting skills on SlumDog Millionaire, i would love to see more of his movies,.

  25. Nelsonbluck表示:

    mexican drugstore online: best online pharmacies in mexico – mexico pharmacies prescription drugs

  26. 4182051表示:

    The Most Effective Reasons For People To Succeed In The Coffeee
    Machine Industry 4182051

  27. Some truly wonderful information, Sword lily I detected this.

  28. WayneCoirl表示:

    mexican rx online: mexico pharmacies prescription drugs – best online pharmacies in mexico

  29. This Is The Replacement Upvc Window Handles Case Study You’ll
    Never Forget glass Replacement for windows

發佈留言

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