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

24,192 Responses

  1. Williszew表示:

    https://interpharmonline.com/# reddit canadian pharmacy

  2. Arthurhow表示:

    http://mexicanpharminter.com/# mexican pharmacy online
    canadapharmacyonline com

  3. Montebeera表示:

    mexican pharmacy online store Mexican Pharm Inter mexican drug stores online

  4. Georgewhend表示:

    india online pharmacy store: online medicine shopping in india – online medicine shopping in india

  5. Arthurhow表示:

    https://indiamedfast.com/# order medicines online india
    canada drugs

  6. Montebeera表示:

    mexican drug stores online buying from online mexican pharmacy mexican pharmacy online store

  7. Arthurhow表示:

    https://interpharmonline.shop/# maple leaf pharmacy in canada
    canadadrugpharmacy com

  8. JamesGag表示:

    india online pharmacy store: cheapest online pharmacy india – IndiaMedFast.com

  9. Williszew表示:

    https://indiamedfast.com/# india pharmacy without prescription

  10. JamesGag表示:

    canadian pharmacy 24h com safe: canadian drugstore online no prescription – certified canadian international pharmacy

  11. Georgewhend表示:

    lowest prescription prices online india: IndiaMedFast – online medicine shopping in india

  12. Georgewhend表示:

    canadian pharmacies that deliver to the us: InterPharmOnline.com – canada rx pharmacy world

  13. Montebeera表示:

    india online pharmacy store india pharmacy without prescription online medicine shopping in india

  14. Williszew表示:

    http://indiamedfast.com/# online pharmacy india

  15. JamesGag表示:

    buying drugs from canada: canadian drugstore online no prescription – canadian pharmacy price checker

  16. Williszew表示:

    http://interpharmonline.com/# canadian pharmacy store

  17. Arthurhow表示:

    https://indiamedfast.com/# india pharmacy without prescription
    canadapharmacyonline com

  18. JamesGag表示:

    india online pharmacy store: online medicine shopping in india – India Med Fast

  19. Georgewhend表示:

    escrow pharmacy canada: InterPharmOnline.com – canadian pharmacy tampa

  20. Georgewhend表示:

    buying prescription drugs from india: online medicine shopping in india – lowest prescription prices online india

  21. Arthurhow表示:

    http://interpharmonline.com/# buying from canadian pharmacies
    medication canadian pharmacy

  22. JamesGag表示:

    India Med Fast: India Med Fast – buying prescription drugs from india

  23. Williszew表示:

    https://indiamedfast.com/# lowest prescription prices online india

  24. Williszew表示:

    http://interpharmonline.com/# best canadian online pharmacy

  25. Arthurhow表示:

    https://mexicanpharminter.com/# reliable mexican pharmacies
    best canadian pharmacy

  26. Montebeera表示:

    reliable canadian pharmacy reviews most reliable canadian online pharmacies canada rx pharmacy

  27. Arthurhow表示:

    https://mexicanpharminter.shop/# mexican pharmacy online
    canadian world pharmacy

  28. Arthurhow表示:

    http://mexicanpharminter.com/# mexican pharmacy online store
    best canadian pharmacy online

  29. JamesGag表示:

    lowest prescription prices online india: IndiaMedFast.com – lowest prescription prices online india

發佈回覆給「Montebeera」的留言 取消回覆

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