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

  1. DavidJeado表示:

    mail order pharmacy india: Healthcare and medicines from India – india pharmacy mail order

  2. Larrylab表示:

    safe canadian pharmacy Canada pharmacy online www canadianonlinepharmacy

  3. Larrylab表示:

    mexico pharmacies prescription drugs Mexico drugstore purple pharmacy mexico price list

  4. DavidJeado表示:

    pharmacies in mexico that ship to usa: Mexico drugstore – best online pharmacies in mexico

  5. Roscoeevern表示:

    http://mexicanpharmgrx.shop/# buying prescription drugs in mexico online

  6. Chasefounc表示:

    canadian world pharmacy: Certified Canadian pharmacies – pet meds without vet prescription canada

  7. Larrylab表示:

    canadian compounding pharmacy List of Canadian pharmacies certified canadian pharmacy

  8. Larrylab表示:

    buying prescription drugs in mexico mexican pharmacy mexico drug stores pharmacies

  9. Larrylab表示:

    Online medicine home delivery Generic Medicine India to USA reputable indian online pharmacy

  10. Roscoeevern表示:

    http://canadianpharmgrx.xyz/# canadianpharmacymeds com

  11. DavidJeado表示:

    canadadrugpharmacy com: Cheapest drug prices Canada – canada drugs online reviews

  12. Larrylab表示:

    buying from online mexican pharmacy mexican pharmacy п»їbest mexican online pharmacies

  13. LamarSix表示:

    best rated canadian pharmacy: List of Canadian pharmacies – canadian family pharmacy

  14. RobertaRous表示:

    http://kamagraiq.com/# п»їkamagra

  15. JohnniePaits表示:

    https://sildenafiliq.xyz/# Cheap Viagra 100mg

  16. DanielElorp表示:

    Cialis over the counter Buy Tadalafil 5mg buy cialis pill

  17. RobertaRous表示:

    https://kamagraiq.shop/# sildenafil oral jelly 100mg kamagra

  18. ChesterAsynC表示:

    Buy Tadalafil 5mg: Generic Cialis without a doctor prescription – buy cialis pill

  19. DanielElorp表示:

    Kamagra Oral Jelly Kamagra 100mg price Kamagra 100mg price

  20. DanielElorp表示:

    Generic Cialis price tadalafil iq Generic Tadalafil 20mg price

  21. Isaacwem表示:

    Buy Tadalafil 10mg: Generic Cialis without a doctor prescription – cheapest cialis

  22. RalphRem表示:

    http://tadalafiliq.shop/# Cialis 20mg price in USA

  23. RobertaRous表示:

    http://tadalafiliq.shop/# Tadalafil price

  24. RalphRem表示:

    http://sildenafiliq.com/# Cheap Sildenafil 100mg

  25. RobertaRous表示:

    http://sildenafiliq.com/# best price for viagra 100mg

  26. DanielElorp表示:

    Buy Tadalafil 5mg tadalafil iq cheapest cialis

  27. Isaacwem表示:

    Cheap generic Viagra: sildenafil iq – buy Viagra over the counter

  28. DanielElorp表示:

    Kamagra 100mg Kamagra Oral Jelly Price cheap kamagra

  29. DanielElorp表示:

    Buy Tadalafil 5mg Buy Cialis online cheapest cialis

  30. RobertaRous表示:

    http://sildenafiliq.com/# Buy Viagra online cheap

發佈留言

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