Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
180
rated 0 times [  182] [ 2]  / answers: 1 / hits: 24450  / 15 Years ago, sat, june 6, 2009, 12:00:00

I have a string in JavaScript and it includes an a tag with an href. I want to remove all links and the text. I know how to just remove the link and leave the inner text but I want to remove the link completely.



For example:



var s = check this out <a href='http://www.google.com'>Click me</a>. cool, huh?;


I would like to use a regex so I'm left with:



s = check this out. cool, huh?;

More From » regex

 Answers
14

This will strip out everything between <a and /a>:



mystr = check this out <a href='http://www.google.com'>Click me</a>. cool, huh?;
alert(mystr.replace(/<ab[^>]*>(.*?)</a>/i,));


It's not really foolproof, but maybe it'll do the trick for your purpose...


[#99368] Wednesday, June 3, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
farrahsavannahl

Total Points: 418
Total Questions: 108
Total Answers: 90

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
farrahsavannahl questions
;