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

5,926 Responses

  1. Danieliteds表示:

    can you get generic clomid prices: when do you take clomid – can you get generic clomid prices

  2. BrianGub表示:

    http://prednisonest.pro/# prednisone tablet 100 mg

  3. AnthonyPreep表示:

    amoxicillin 500mg without prescription amoxicillin 500mg for sale uk where to buy amoxicillin pharmacy

  4. Waynerat表示:

    cost of generic clomid: can i get cheap clomid online – cost of cheap clomid pill

  5. Williamces表示:

    can i get cheap clomid online: clomid over the counter – where can i get generic clomid no prescription

  6. BrianGub表示:

    https://prednisonest.pro/# buy prednisone nz

  7. Williamces表示:

    amoxicillin buy no prescription: amoxicillin 250 mg – buying amoxicillin in mexico

  8. IrwinGlync表示:

    can you get clomid now: where buy clomid without insurance – cheap clomid tablets

  9. Williamces表示:

    can you buy prednisone over the counter uk: side effects prednisone – 3000mg prednisone

  10. Danieliteds表示:

    buy amoxicillin 500mg capsules uk: amoxicillin warnings – amoxicillin 500mg for sale uk

  11. Waynerat表示:

    buy amoxicillin 500mg canada: amoxicillin 500mg capsules – amoxicillin pills 500 mg

  12. Waynerat表示:

    cost of generic clomid without insurance: how can i get cheap clomid without a prescription – where buy generic clomid online

  13. BrianGub表示:

    http://prednisonest.pro/# buy prednisone 50 mg

  14. Williamces表示:

    where can i get generic clomid without rx: clomid dosage for men – cheap clomid no prescription

  15. BrianGub表示:

    https://amoxilst.pro/# can you buy amoxicillin over the counter canada

  16. Williamces表示:

    prednisone 20mg prescription cost: prednisone side effects – buy prednisone no prescription

發佈留言

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