Regex in Javascript to remove links

后端 未结 6 1739
南旧
南旧 2020-12-06 17:22

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 r

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 17:32

    Just to clarify, in order to strip link tags and leave everything between them untouched, it is a two step process - remove the opening tag, then remove the closing tag.

    txt.replace(/]*>/i,"").replace(/<\/a>/i, "");
    

    Working sample:

    
    
    

    Here's the text!

提交回复
热议问题