title: How do I make Regex capture only named groups
body: <p>According to <code>Regex</code> documentation, using <code>RegexOptions.ExplicitCapture</code> makes the Regex only match named groups like <code>(?&lt;groupName&gt;...)</code>; but in action it does something a little bit different.  </p>
  
  <p>Consider these lines of code:</p>
  
  <pre><code>static void Main(string[] args) {
      Regex r = new Regex(
          @"(?&lt;code&gt;^(?&lt;l1&gt;[\d]{2})/(?&lt;l2&gt;[\d]{3})/(?&lt;l3&gt;[\d]{2})$|^(?&lt;l1&gt;[\d]{2})/(?&lt;l2&gt;[\d]{3})$|(?&lt;l1&gt;^[\d]{2}$))"
          , RegexOptions.ExplicitCapture
      );
      var x = r.Match("32/123/03");
      r.GetGroupNames().ToList().ForEach(gn =&gt; {
          Console.WriteLine("GroupName:{0,5} --&gt; Value: {1}", gn, x.Groups[gn].Success ? x.Groups[gn].Value : "");
      });
  }
  </code></pre>
  
  <p>When you run this snippet you'll see the result contains a group named <strong>0</strong> while I don't have a group named 0 in my regex!  </p>
  
  <pre><code>GroupName:    0 --&gt; Value: 32/123/03  
  GroupName: code --&gt; Value: 32/123/03  
  GroupName:   l1 --&gt; Value: 32  
  GroupName:   l2 --&gt; Value: 123  
  GroupName:   l3 --&gt; Value: 03  
  Press any key to continue . . .  
  </code></pre>
  
  <p>Could somebody please explain this behavior to me?</p>