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

15,769 Responses

  1. Andrew表示:

    How Do I Explain Double Glazed Windows Milton Keynes To A Five-Year-Old locked in a room
    milton keynes milton keynes (Andrew)

  2. LloydNoice表示:

    http://kampharm.shop/# buy kamagra oral jelly Kam Pharm

  3. Сервисный центр предлагает починить кофемашины supra ремонт кофемашин supra в москве

  4. Тут можно преобрести оружейные сейфы и шкафы оружейный сейф купить москва

  5. Thou shalt break them with a rod of iron; Thou shalt dash them in items like a potter’s vessel.

  6. Line 8 was the final line adopted for the agreement of 30 March 1898, and consisted of a route between Opéra and Porte d’Auteuil by way of Grenelle.

  7. Hopefully, you discovered something that caught your curiosity, and you checked some people off your buying record.

  8. The diamonds and stones formed lovely intricate patterns from head to toe, glittering over the physique-hugging bodice and across the plunging neckline.

  9. Do you need to help native farmers and artisans while having fun with recent, seasonal produce?

  10. Ernest Daryl Lindsay, of South Yarra, Victoria.

  11. Substituting a typical-dimension whirlpool tub for a bathtub is a luxurious leap ahead.

  12. Сервисный центр предлагает центр ремонта видеокарты foxconn ремонт видеокарты foxconn на дому

  13. Francis Ernest Piper, President of the Regulation Society, State of South Australia.

  14. Сервисный центр предлагает мастер по ремонту холодильника mabe качественный ремонт холодильников mabe

  15. Тут можно преобрести оружейный сейф для охотничьего ружья оружейный сейф интернет магазин

  16. You’ll Never Be Able To Figure Out This Realistic Sex Dolls For Sale’s Tricks realistic Sex Dolls for sale

  17. Sir Keir responded: ‘I am completely happy to assist the chief of the Opposition.

  18. Тут можно преобрести ящик для оружия купить купить сейф для охотничьего ружья

  19. We don’t spam! Read our privateness policy for more information.

  20. Amazing Comment to Web Publication Input

    Amazing write-up! I’m certainly delighting in the information here.
    Possess you previously deliberated on receiving inside web-based gambling gaming?
    Evolution Gaming Site is a fantastic company including a diverse collection of
    premium interactive croupier experiences. The complete outing is outstandingly riveting and authentic, it feels resembling you’re directly within the casino as a part of the
    proper casino.

    Provided you’re keen in exploring it furthermore, I’d be elated to share my recommendation address.
    The Evolution Gaming Platform features a great new player promotion for new newest bettors.
    It is undisputedly advantageous considering further should you’re wanting a fresh internet wagering affair.

    Recognition once more in favor of this web publication content.

    Sustain going the efforts!

    my webpage … gambling addiction

  21. Not included in the construction contract were the conversion and restoration of the streets after laying the tracks and erecting the depot at Urachstraße; this work was undertaken by town and municipal constructing authorities.

  22. CarrollUnton表示:

    deneme bonusu veren siteler betturkey betturkey.com https://casinositeleri.win/# Casino Siteleri

  23. Mr Molner, a local of Chicago, is the top of mergers and acquisitions at funding financial institution and securities agency Brown Brothers Harriman.

  24. Anybody with access to a web browser can view your interactive flooring plan from a Laptop, Mac, or most mobile devices.

  25. John Cormack, Principal, Bootle Technical School, Lancashire.

  26. This is the rationale to keep away from quick layers.

  27. 12 Companies Leading The Way In Upvc Windows And Doors Upvc window Repair

  28. Shaul Kimhi and Shmuel Even, writing of events right down to 2003, have argued that kids and youths who engage in terrorist acts form a part of a fourth category by motivation, which they define as “the exploited”.

  29. notes.io表示:

    The world of intense gaming has undergone a remarkable
    change in recent years, with the rise of esports as a global fad .

    Amidst this rapidly evolving landscape, one name has emerged as a groundbreaker – Spade Gaming.

    Spade Gaming is a force to be reckoned with, a gaming
    enterprise that has carved out a unique specialty
    for itself by blending cutting-edge advancement
    , strategic planning , and a determined commitment to perfection .

    Established with the goal of rethinking the boundaries of fierce gaming, Spade Gaming has quickly become a beacon of ingenuity
    , driving the realm forward with its innovative approach and unflagging dedication.

    At the foundation of Spade Gaming’s accomplishment lies its unyielding concentration on athlete
    development and collective building. The enterprise has cultivated an
    environment that fosters and strengthens its individuals, providing them with the tools , tutelage,
    and help they need to accomplish new peaks .

    But Spade Gaming’s consequence extends far outside the confines of the constraints of the
    game by itself . The establishment has also cemented itself as a
    innovator in the area of reporting creation, utilizing
    its extensive array of masterful professionals to craft captivating
    and engaging information that resonates among aficionados
    reaching the international community .

    On top of that , Spade Gaming’s fealty to community stewardship
    and public collaboration defines it apart from its rivals .

    The establishment has capitalized on its influence to
    promote important drives, maximizing its impact and prestige to make
    a meaningful change in the realm of esports and reaching farther .

    As the electronic sports industry continues to transform , Spade Gaming towers as a shining
    prototype of that which can be obtained when perspective ,
    creativity , and a unyielding ambition of
    dominance synergize.

    In the epoch to come , as the world of cutthroat
    gaming presses forward to enthrall audiences and revolutionize the manner we
    participate with amusement , Spade Gaming will without a doubt
    prevail at the vanguard , leading the campaign and building a
    pioneering chapter in the constantly changing
    domain of esports.

    Here is my homepage; Bonuses and promotions – notes.io,

發佈留言

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