title: Regex - loop through matches
body: <p>I'm parsing a sgml file. Each entry is something like this:</p>
  
  <pre><code>&lt;key n=1&gt;xzsd:test
      &lt;sk id=1 hi=1&gt;test
          &lt;tag1&gt;.............&lt;/tag1&gt;
          &lt;tag2&gt;.............&lt;/tag2&gt;
           ................
      &lt;/sk&gt;
      &lt;sk id=2&gt;test2
          &lt;tag1&gt;.............&lt;/tag1&gt;
          &lt;tag2&gt;.............&lt;/tag2&gt;
           ................
      &lt;/sk&gt;
  &lt;/key&gt;
  </code></pre>
  
  <p>I want to replace <code>&lt;key n=1&gt;...&lt;/key&gt;</code> with some HTML markup. I'm currently replacing tag by tag, but it would probably be more efficient to just retrieve everything inside the <code>&lt;key&gt;</code> tag.</p>
  
  <p>How could I make this code compile:</p>
  
  <pre><code>entry = Regex.Replace(entry, "&lt;key .*?&gt;.*&lt;/key&gt;", "&lt;div class='key'&gt;$2&lt;div&gt;");//Only interested in the second match.
  Regex skReg = new Regex(@"&lt;sk...&gt;", RegexOptions.Compiled);
  foreach (Match ItemMatch in ItemRegex.Matches(entry))
  {
         //Do parsing of contents of each sk tag
  }
  </code></pre>
  
  <p>The sgml does not have any newlines</p>