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

434 Responses

  1. There is obviously a bunch to realize about this. I assume you made some nice points in features also.

  2. propecia rival crossword buy propecia online europe should i take propecia reddit dr who will prescribe propecia to female patients

  3. cenforce 100mg generic cenforce soft cenforce 200 отзывы cenforc

  4. cialis 2.5mg cialis sur ordonnance ou pas cialis ne fait pas d’effet comment demander du cialis a son medecin

  5. staxyn vs levitra viagra and cialis australia kamagra oral jelly review forum cialis how long to take effect

  6. uxqpsjqj表示:

    hydroxychloroquine sulfate 200mg purchase plaquenil online

  7. order cheap online levitra where can i buy levitra levitra bucodispersable levitra 20 milligrams

  8. neurontin opiate how much is gabapentin 300 mg neurontin withdrawal symptoms how long what is gabapentin used for?

  9. Great blog! Do you have any hints for aspiring writers? I’m hoping to start my own blog soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely confused .. Any tips? Appreciate it!

  10. lzbsoaqx表示:

    hydroxychloroquine in canada for sale http://hydroxychloroquinex.com/

發佈留言

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