a='<p>test<br>aaa</p>'//expected result"test<br>aaa"
b='>test<em>test</em>one more test'//expected result"test<em>test</em>one more test"
c='<a href="#">test test<b>test</b>test</a>'//expected result"test test<b>test</b>test"

1 Answers 1

function DeleteTags(str) {
  return str.match(/(^[^>] *>)? *(.*?) *(<[\/a-z>] *)? $/)[2];
}
  • Thank you very much. – Chinese Paintball Feb 9 '19 at 16:23
  • Chinese Paintball, just note that passing an invalid parameter to a function will result in an error if you are going to use it in production, you should consider checking or handling errors – Dangerous17 Feb 9 '19 at 20:31
  • Dangerous17, Thank you. Data is transmitted from a trusted source. I have already used it. Everything works fine, except for the following case:
    >test test test </p
    – Chinese Paintball Feb 9 '19 at 20:52
  • Chinese Paintball, yes, by the condition it is not clear what is considered an html-tag, here is an updated version that includes your last case:
    function DeleteTags (str) { return str.match (/(^ [^>] *>)? * (. *?) * (<[\/a-z>] *)? $/) [2];}

    – Dangerous17 Feb 9 '19 at 23:20
  • Dangerous17, thank you! – Chinese Paintball Feb 11 '19 at 10:21