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,828 Responses

  1. 10 Sites To Help Be A Pro In Vauxhall Car Keys Vauxhall Key Programming Cost

  2. The given substance of this blog article is extremely
    captivating . I delighted in the way you examined
    the different issues so thoroughly and distinctly .
    You helped me gain fresh perspectives that
    I had not pondered before. I’m thankful for disseminating your knowledge and
    adeptness – it has equipped me to learn even more.

    I uniquely relished the novel standpoints you introduced ,
    which enlarged my understanding and intellect in worthwhile courses.
    This blog is coherent and captivating
    , which is essential for information of this caliber .

    I wish to read more of your work in the days to come , as I’m
    confident it is sure to continue to be illuminating and help me persist in improving.
    Thanks again !

    Also visit my web-site online casino wire transfers

  3. Jorgeagopy表示:

    india pharmacy mail order: indian pharm 24 – indianpharmacy com

  4. The Split was first movie to be given an R ranking under the newly instituted MPAA rating system.

  5. At the moment, a gallon will set you back around $3.32.

  6. Still, this lighthearted comedy webtoon is stuffed with mirth and warmth.

  7. Williamagric表示:

    prescription drugs without doctor approval http://pharm24.pro/# ed medication online

  8. Davidhaf表示:

    Тут можно преобрести сейф несгораемый огнеупорные сейфы

  9. Davidhaf表示:

    Тут можно преобрести несгораемые сейфы противопожарный сейф

  10. Howson returned to Putney and resumed her work there, usually restoring medieval glass.

  11. Adelaida表示:

    The Underrated Companies To Follow In The Best Lawyer For Accidents Industry lawyer near me accident (Adelaida)

  12. You will need recognizable names in your title although, as a result of…

  13. Jay Hong’s design was inspired by mannequin Hong Jae-yeol; DG was inspired by G-Dragon; Oliver Jang’s design was inspired by Jang Dongwoo, ARU by singer IU, Jace is modeled by former 2PM leader and singer Jay Park.

  14. One in a mild blue and mushy pink taffeta dress; the other in a lovely buttercup yellow gown with floral decorations.

  15. If nonetheless not clear, test filter operation.

  16. British Society of Grasp Glass Painters.

  17. Check out the posts by Cesar Diaz (SRV’s amp tech) about Stevie’s amp mods!

  18. 11 Creative Ways To Write About Car Boot Scooters collapsible mobility scooter

  19. Each keystroke is a mini victory, and seeing your thoughts inked onto paper in real-time provides a complete new dimension to the creative course of.

  20. 咲く 古語表示:

    Query: If you have been to give a French poodle a name, what would it’s?

  21. DevonPhack表示:

    https://indianpharm24.pro/# indian pharmacy
    ed treatment review

  22. We are getting nearer to accomplished with each seam and this little man might be ready to play.

  23. 現在 ドル表示:

    Once i sat down to really compose my listings, I first turned to the contents web page of each problem of Look.

  24. Let’s think of it as a row by row.

  25. Who Is Responsible For An Rollators – 3 Wheeled Budget?

    Twelve Top Ways To Spend Your Money outdoor 3 wheel Rollator

  26. Guidelines for classification: 1) points; 2) aim difference; 3) number of goals scored.

  27. Jorgeagopy表示:

    buy medicines online in india: Best online Indian pharmacy – cheapest online pharmacy india

  28. Is the RCA VideoDisc system older than the MCA DiscoVision reflective optical disc system (later known as LaserDisc)?

  29. The three lights involved cover the Nativity, Crucifixion and Resurrection.

  30. BrandonSaisy表示:

    mexico drug stores pharmacies: mexico pharmacy – mexican drugstore online

發佈留言

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