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

6,913 Responses

  1. WilliamRhype表示:

    https://nolvadex.life/# tamoxifen rash

  2. RandallTaulp表示:

    ciprofloxacin 500 mg tablet price: buy cipro – buy cipro online

  3. Ronaldpsymn表示:

    http://nolvadex.life/# aromatase inhibitor tamoxifen

  4. RandallTaulp表示:

    where can i purchase lisinopril: lisinopril online prescription – lisinopril 1.25

  5. Davidtes表示:

    Misoprostol 200 mg buy online п»їcytotec pills online cytotec online

  6. RandallTaulp表示:

    cytotec pills buy online: buy cytotec online – buy cytotec over the counter

  7. WilliamRhype表示:

    http://nolvadex.life/# tamoxifen benefits

  8. WilliamRhype表示:

    https://finasteride.store/# get propecia tablets

  9. Davidtes表示:

    buy cytotec pills online cheap buy cytotec over the counter buy cytotec pills online cheap

  10. WilliamRhype表示:

    https://nolvadex.life/# natural alternatives to tamoxifen

  11. RandallTaulp表示:

    tamoxifen rash: buy nolvadex online – cost of tamoxifen

  12. Ronaldpsymn表示:

    https://finasteride.store/# generic propecia price

  13. RandallTaulp表示:

    order cytotec online: buy cytotec pills online cheap – buy cytotec online fast delivery

發佈留言

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