title: Using multiple regexes to capture matching nested xml tags
body: <p>suppose I have an xml file that contains tags nested inside themselves, eg</p>
  <pre><code>&lt;TAG&gt;one&lt;TAG&gt;two&lt;/TAG&gt;one&lt;/TAG&gt;
  </code></pre>
  <p>From <a href="http://www.regular-expressions.info/examples.html" rel="nofollow noreferrer">this page</a>, I have two examples of regex expressions that don't properly match this string, eg you will get</p>
  <pre><code>&lt;TAG&gt;one&lt;TAG&gt;two&lt;/TAG&gt;
  </code></pre>
  <p>which is not balanced. According to Google, it's not possible to find a regex that will parse html correctly, eg <a href="https://stackoverflow.com/a/4383297/3782261">here</a> or <a href="https://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not/590789">here</a>.</p>
  <blockquote>
  <p>Entire HTML parsing is not possible with regular expressions, since it depends on matching the opening and the closing tag which is not possible with regexps.</p>
  <p>Regular expressions can only match regular languages but HTML is a context-free language. The only thing you can do with regexps on HTML is heuristics but that will not work on every condition. It should be possible to present a HTML file that will be matched wrongly by any regular expression.</p>
  </blockquote>
  <p>That's a nice clear-cut theoretical answer, but it got me thinking: <I>would it be possible programmatically, using multiple regexes and/or loops?</I></p>