Regular Expression: exclude html tags from “content”

前端 未结 3 1755
轻奢々
轻奢々 2020-12-06 22:14

One friend asked me this and as my knowledge on RegExp is not so good yet here I am.

How can exclude the HTML tags from this string?

re
na&l
相关标签:
3条回答
  • 2020-12-06 22:16

    this is a quick way to do it:

    var content = "re<br>na<br>to<br>galvao";
    content = content.replace(/<[^>]*>/g,'');
    
    0 讨论(0)
  • 2020-12-06 22:31

    Match all html tags with this regex:

     <("[^"]*?"|'[^']*?'|[^'">])*>
    

    see demo here: http://regex101.com/r/fA0oT4

    0 讨论(0)
  • 2020-12-06 22:41

    You could use a non-greedy match. According to the answer to this question, in javascript it is *?

    So, assuming this is the only problem with your regex, it should work with

    (.*?)<.*?>(.*?)
    
    0 讨论(0)
提交回复
热议问题