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

17,288 Responses

  1. Willardvem表示:

    http://mexicanpharmi.com/# mexican pharmaceuticals online

  2. StephenJem表示:

    http://canadianpharmi.com/# male enhancement

  3. MatthewHen表示:

    indian pharmacy paypal Online India pharmacy india online pharmacy

  4. StephenJem表示:

    https://mexicanpharmi.com/# mexican border pharmacies shipping to usa

  5. Willardvem表示:

    http://indiapharmi.com/# п»їlegitimate online pharmacies india

  6. Willardvem表示:

    http://canadianpharmi.com/# erectile dysfunction pills

  7. Jeffreyvop表示:

    cheap ed pills: Canada Pharmacy – cheap erectile dysfunction pill

  8. MatthewHen表示:

    buying prescription drugs in mexico online Purple pharmacy online ordering purple pharmacy mexico price list

  9. вывод из запоя санкт-петербург вывод из запоя санкт-петербург .

  10. Willardvem表示:

    https://mexicanpharmi.com/# medication from mexico pharmacy

  11. Ernestzow表示:

    online pharmacy india: india pharmi – world pharmacy india

  12. Ernestzow表示:

    world pharmacy india: Best Indian pharmacy – top 10 online pharmacy in india

  13. MatthewHen表示:

    mexican border pharmacies shipping to usa mexican pharmacy mexican drugstore online

  14. Willardvem表示:

    http://indiapharmi.com/# indian pharmacy

  15. MatthewHen表示:

    drugs online Canadian pharmacy prices vitality ed pills

  16. Jeffreyvop表示:

    cheap drugs: canadian pharmacy – online drugs

  17. брокерские услуги по таможенному оформлению брокерские услуги по таможенному оформлению .

  18. Jeffreyvop表示:

    buying from online mexican pharmacy: Online Mexican pharmacy – mexican rx online

  19. Jeffreyvop表示:

    indian pharmacy paypal: Indian online pharmacy ship to USA – reputable indian online pharmacy

  20. Jeffreyvop表示:

    indianpharmacy com: Online medicine home delivery – online shopping pharmacy india

  21. MatthewHen表示:

    medicine in mexico pharmacies Legit online Mexican pharmacy mexican rx online

  22. Ernestzow表示:

    prescription drugs without doctor approval: Best Canadian online pharmacy – buy canadian drugs

  23. MatthewHen表示:

    reputable mexican pharmacies online Mexican pharmacies that ship to the United States mexican pharmaceuticals online

  24. StephenJem表示:

    https://canadianpharmi.com/# best male enhancement pills

  25. Ernestzow表示:

    online meds for ed: Canada Pharmacy – viagra vs cialis bodybuilding

發佈留言

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