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

20,173 Responses

  1. Davidmoits表示:

    easy canadian pharm: canadian drug prices – canadian pharmacy 24h com

  2. Porterfax表示:

    mexican online pharmacies prescription drugs xxl mexican pharm mexican drugstore online

  3. Porterfax表示:

    Mega India Pharm MegaIndiaPharm MegaIndiaPharm

  4. WillieRap表示:

    Cheapest online pharmacy: canadian pharmacy without prescription – Best online pharmacy

  5. Davidmoits表示:

    xxl mexican pharm: xxl mexican pharm – п»їbest mexican online pharmacies

  6. Davidmoits表示:

    Cheapest online pharmacy: Cheapest online pharmacy – online pharmacy delivery usa

  7. Davidmoits表示:

    discount drug pharmacy: discount drug pharmacy – discount drug pharmacy

  8. Charleskepsy表示:

    best online pharmacy no prescription https://megaindiapharm.com/# Mega India Pharm

  9. Charleskepsy表示:

    legal online pharmacy coupon code https://discountdrugmart.pro/# discount drug mart

  10. Davidmoits表示:

    discount drug pharmacy: discount drug mart pharmacy – drugmart

  11. MichaelGeony表示:

    pharmacy coupons http://discountdrugmart.pro/# discount drug pharmacy

  12. Charleskepsy表示:

    online pharmacy no prescription http://megaindiapharm.com/# Mega India Pharm

  13. WillieRap表示:

    easy canadian pharm: easy canadian pharm – easy canadian pharm

  14. Davidmoits表示:

    discount drug mart pharmacy: discount drug mart pharmacy – canadian pharmacy discount coupon

  15. Charleskepsy表示:

    best no prescription pharmacy https://xxlmexicanpharm.com/# medication from mexico pharmacy

  16. WillieRap表示:

    pharmacies in mexico that ship to usa: xxl mexican pharm – xxl mexican pharm

  17. WillieRap表示:

    discount drugs: discount drug mart – drug mart

  18. WillieRap表示:

    Cheapest online pharmacy: family pharmacy – prescription drugs online

  19. Davidmoits表示:

    canadian pharmacy review: easy canadian pharm – canadianpharmacyworld com

發佈留言

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