Remove HTML tags in script
<p>I've found this piece of code on the internet. It takes a sentence and makes every single word into link with this word. But it has weak side: if a sentence has HTML in it, this script doesn't remove it.</p>

<p>For example: it replaces '<code>&lt;b&gt;asserted&lt;/b&gt;</code>' with '<code>http://www.merriam-webster.com/dictionary/&lt;b&gt;asserted&lt;/b&gt;</code>'</p>

<p>Could you please tell me what to change in this code for it to change '<code>&lt;b&gt;asserted&lt;/b&gt;</code>' to '<code>http://www.merriam-webster.com/dictionary/asserted</code>'.</p>

<pre><code>var content = document.getElementById("sentence").innerHTML;

var punctuationless = content.replace(/[.,\/#!$%\Ø^?&amp;\*;:{}=\-_`~()ââ"]/g, "");
var mixedCase = punctuationless.replace(/\s{2,}/g);
var finalString = mixedCase.toLowerCase();

var words = (finalString).split(" ");

var punctuatedWords = (content).split(" ");

var processed = "";
for (i = 0; i &lt; words.length; i++) {
    processed += "&lt;a href = \"http://www.merriam-webster.com/dictionary/" + words[i] + "\"&gt;";
    processed += punctuatedWords[i];
    processed += "&lt;/a&gt; ";
}

document.getElementById("sentence").innerHTML = processed;
</code></pre>

<pre><code>function stripAllHtml(str) {
  if (!str || !str.length) return ''

  str = str.replace(/&lt;script.*?&gt;.*?&lt;\/script&gt;/igm, '')

  let tmp = document.createElement("DIV");
  tmp.innerHTML = str;

  return tmp.textContent || tmp.innerText || "";
}

stripAllHtml('&lt;a&gt;test&lt;/a&gt;')
</code></pre>

<p>This function will strip all the HTML and return only text.</p>

<p>Hopefully, this will work for you</p>

javascript python regex replace