title: Matching pair tag with regex
body: <p>I'm trying to retrieve specific tags with their content out of an xhtml document, but it's matching the wrong ending tags.</p>
  
  <p>In the following content:</p>
  
  <pre><code>&lt;cache_namespace name="content"&gt;
      &lt;content_block id="15"&gt;
      some content here
  
          &lt;cache_namespace name="user"&gt;
              &lt;content_block id="welcome"&gt;
              Welcome Apikot!
              &lt;/content_block&gt;
          &lt;/cache_namespace&gt;
      &lt;/content_block&gt;
  &lt;/cache_namespace&gt;
  </code></pre>
  
  <p>The content_block ending tag for id="welcome" actually get's matched as the ending tag of the first opening content_block tag.</p>
  
  <p>The regex I'm using is:</p>
  
  <pre><code>/&lt;content_block id="(.*)"&gt;([\w\W]*?)&lt;\/content_block&gt;/i
  </code></pre>
  
  <p>Any pointers as to where I'm failing?</p>