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

11,799 Responses

  1. Если вы искали где отремонтировать сломаную технику, обратите внимание – тех профи

  2. Throughout the awesome scheme of things you secure a B+ with regard to hard work. Where exactly you lost everybody was in your facts. As as the maxim goes, the devil is in the details… And it couldn’t be much more correct in this article. Having said that, let me say to you just what did work. The authoring is certainly quite persuasive and this is probably the reason why I am taking the effort to comment. I do not make it a regular habit of doing that. Next, even though I can easily see a leaps in reasoning you come up with, I am not really certain of exactly how you seem to unite your points which inturn produce the actual conclusion. For the moment I will, no doubt yield to your point but wish in the future you actually link the dots much better.

  3. Construction workers, industrial workers, military veterans and others who worked with asbestos legal-contaminated products are at risk of developing mesothelioma.

  4. Why You Should Focus On Enhancing Fridge Freezer Frost
    Free 50/50 Under counter fridge freezer 50/50 (https://trade-britanica.trade)

  5. The 10 Most Terrifying Things About Mini Cooper Keys Mini cooper keys

  6. Scottdiz表示:

    1win: 1win вход – 1вин

  7. Warrenmof表示:

    http://pin-up.diy/# пин ап зеркало

  8. Retro Frost Free Fridge Freezer Tools To Ease Your Daily Life Retro Frost Free Fridge Freezer Trick That
    Everybody Should Be Able To retro Frost free fridge freezer

  9. Scottdiz表示:

    1вин официальный сайт: 1вин официальный сайт – 1win

  10. 15 Latest Trends And Trends In ADHD Treatment Adults when Adhd Goes untreated

  11. Its such as you read my mind! You appear to grasp so much about this, such as you wrote the guide in it or something. I feel that you could do with a few percent to force the message house a little bit, but instead of that, this is magnificent blog. A fantastic read. I will certainly be back.

  12. Genial der Artikel ist wirklich gut mach weiter so Viele Grüsse Saloma

  13. Guide To Situs Togel Dan Slot Terpercaya: The Intermediate Guide The Steps To Situs Togel Dan Slot
    Terpercaya Situs Togel Dan Slot Terpercaya

  14. Rod表示:

    15 Top Twitter Accounts To Discover Key Fob Programming Near Me car key programer
    near me (Rod)

  15. Warrenmof表示:

    http://1win.directory/# 1вин официальный сайт

  16. Scottdiz表示:

    1win зеркало: 1win зеркало – 1вин официальный сайт

  17. keys表示:

    3 Ways In Which The Locksmith For Car Can Affect Your Life keys

  18. Thanks for your insight for the great posting. I am glad I have taken the time to see this.

  19. hptuners表示:

    Spot on with this write-up, I honestly think this amazing site needs a great deal more attention. I’ll probably be returning to read through more, thanks for the information.

  20. Scottdiz表示:

    казино вавада: казино вавада – вавада рабочее зеркало

  21. Hi, i think that i saw you visited my blog thus i came to “return the favor”.I am attempting to find things to improve my web site!I suppose its ok to use a few of your ideas!!

  22. Scottdiz表示:

    1win: 1win – 1вин официальный сайт

  23. Hi, Neat post. There is a problem with your web site in internet explorer, would check this… IE still is the market leader and a big portion of people will miss your magnificent writing because of this problem.

  24. This Week’s Top Stories About Black Chest Freezers Which chest freezer

發佈留言

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