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

  1. Does the [i]viagra commercial saturday night live[/i] wipeabide you the filamentous respiratorya as the percs.

  2. An In-Depth Look Back The Conversations People Had
    About Upvc Door And Windows 20 Years Ago flush Casement upvc Windows

  3. Nelsonbluck表示:

    buying prescription drugs in mexico: medicine in mexico pharmacies – mexican border pharmacies shipping to usa

  4. Nelsonbluck表示:

    reputable mexican pharmacies online: buying prescription drugs in mexico – buying prescription drugs in mexico online

  5. Arnoldten表示:

    medication from mexico pharmacy mexican drugstore online mexican drugstore online

  6. WayneCoirl表示:

    mexican drugstore online: purple pharmacy mexico price list – mexican rx online

  7. DominicJaw表示:

    medication from mexico pharmacy: mexican rx online – buying prescription drugs in mexico

  8. I as well believe hence , perfectly indited post! .

  9. Five Killer Quora Answers To Pod And Bean Coffee Machine pod and bean coffee machine

  10. Nelsonbluck表示:

    mexican drugstore online: buying from online mexican pharmacy – buying prescription drugs in mexico online

  11. 10 Things Everyone Hates About Truck Accident Injury Lawyer truck accident lawyers new orleans (http://rutelochki.Ru/)

  12. WayneCoirl表示:

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

  13. DominicJaw表示:

    buying prescription drugs in mexico online: reputable mexican pharmacies online – best online pharmacies in mexico

  14. WayneCoirl表示:

    purple pharmacy mexico price list: pharmacies in mexico that ship to usa – reputable mexican pharmacies online

  15. I’d forever want to be update on new posts on this website , saved to favorites ! .

  16. DominicJaw表示:

    mexican border pharmacies shipping to usa: purple pharmacy mexico price list – medication from mexico pharmacy

  17. RichardWrifs表示:

    https://mexicandeliverypharma.com/# mexican pharmaceuticals online

  18. RichardWrifs表示:

    http://mexicandeliverypharma.com/# best online pharmacies in mexico

  19. Nelsonbluck表示:

    mexico drug stores pharmacies: medication from mexico pharmacy – п»їbest mexican online pharmacies

  20. Nelsonbluck表示:

    mexican border pharmacies shipping to usa: mexican drugstore online – mexican drugstore online

  21. Arnoldten表示:

    buying prescription drugs in mexico online mexico drug stores pharmacies buying from online mexican pharmacy

  22. This is really interesting, You’re quite a competent article author. I have signed up with your feed and furthermore , count on reading all of your extraordinary write-ups. In addition, I’ve shared your webpage throughout our social networks.

  23. WayneCoirl表示:

    buying from online mexican pharmacy: buying prescription drugs in mexico – mexico drug stores pharmacies

  24. DominicJaw表示:

    buying from online mexican pharmacy: mexican rx online – mexico drug stores pharmacies

  25. “There is some validity but I will hold judgment until I look into it further”

  26. Nelsonbluck表示:

    purple pharmacy mexico price list: mexican pharmaceuticals online – purple pharmacy mexico price list

  27. WayneCoirl表示:

    mexican border pharmacies shipping to usa: п»їbest mexican online pharmacies – buying prescription drugs in mexico online

  28. DominicJaw表示:

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

  29. WayneCoirl表示:

    pharmacies in mexico that ship to usa: mexican pharmaceuticals online – mexican drugstore online

  30. DominicJaw表示:

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

發佈留言

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