title: Javascript regex to remove unmatched closing HTML tags?
body: <p>I'm trying to remove the excessive closing tags in javascript and anything that follows after that.</p>
  
  <p>Here is a possible sample:</p>
  
  <pre><code>&lt;div class="dummy"&gt;
      &lt;div class="main"&gt;
          &lt;div&gt;&lt;/div&gt;
          &lt;img src="a.jpg"&gt;
          &lt;br&gt;
          &lt;img src="b.jpg /&gt;
          &lt;strong&gt;
              &lt;span&gt;text&lt;/span&gt;
          &lt;/strong&gt;
      &lt;/div&gt;
  &lt;/div&gt;
      ***excessive tags below***
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="footer"&gt;
      text
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any ideas about how to do it efficiently?
  The part I want to extract is always a div, but the problem is that it may have as many nested divs, and I'm not sure how to deal with this scenario.</p>
  
  <p>If it can be done in multiple steps or with callbacks is also fine, as long as it works.</p>
  
  <p><strong>Edit</strong>
  My question is actually easier than it seems.
  The sample always starts with the div that I want to extract.
  So all I need is to find the matching  closing tag, and filter anything that follows.
  Don't care about any other tags...</p>