Isaac Isaac - 6 months ago 7
HTML Question

Regex for Removing HTML Links

I am trying to create a regex to remove all links from a HTML table so that the links will not display when the table is exported to excel. I am using the line of JavaScript below which removes everything except the link text. Any suggestions on how to remove the link text as well? Thanks.

tableHTML = tableHTML.replace(/<a[^>]*>|<\/a>/g, "")

Answer

I'm not sure what are you trying to do, But if you want to remove all links, this pattern would help you:

/<a.*?a>/gm

Online Demo


Full Code:

tableHTML = tableHTML.replace(/<a.*?a>/gm, "")
Comments