title: C# Regex not matching Regex101
body: <p>I have a string which I'm trying to match with Regex in C#.</p>
  
  <p>The string is <code>Hello1004,"7"</code>.</p>
  
  <p>I'm creating the Regex with</p>
  
  <pre><code>var reg = new Regex(@"hello\s*\[?\s*,?\s*(?&lt;group1&gt;\d+)\s*,\s*""(?&lt;group2&gt;[^""]+)""", RegexOptions.IgnoreCase);
  </code></pre>
  
  <p>(There may be multiple spaces, a <code>[</code> or a <code>,</code> before <code>1004</code>.)</p>
  
  <p><code>1004</code> may not always be <code>1004</code>, but it will always be a 4-digit number.</p>
  
  <p>What I'm trying to get is:</p>
  
  <ul>
  <li>group1: <code>1004</code></li>
  <li>group2: <code>7</code></li>
  </ul>
  
  <p>You can see a Regex101 demo <a href="https://regex101.com/r/y02qoD/2" rel="nofollow noreferrer">here</a>.</p>
  
  <p>It works perfectly in the demo, but when doing</p>
  
  <pre><code>foreach (var match in reg.Matches(text))
  {
      var group1 = match.Groups["group1"]?.Value;
      var group2 = match.Groups["group2"]?.Value;
  }
  </code></pre>
  
  <p><code>group1</code> is empty and <code>group2</code> has <code>1004</code> in it. If I put a space between <code>Hello</code> and <code>1004</code> it works fine in C#.</p>
  
  <p>Can anyone explain why I'm getting this discrepancy between the two?</p>
  
  <p>I'm using Visual Studio 2017, .Net Framework 4.</p>