title: Add an element in a list by matching with a regex
body: <p>I am an intern and I am developing a solution in C# which allows me to retrieve a string of characters in a cell from an excel file. Once this string has been retrieved, the elements of this string must be separated into 2 other lists (sample and reference) using a regex.
  It means that if an element of this string corresponds to the regex, it must be sent in the &quot;sample&quot; list and if it does not correspond, it must be sent in the &quot;reference list&quot;.</p>
  <p>For several days, I have been trying to fix this problem but I cannot display the &quot;sample&quot; list where the elements should correspond to the regex. It does not work correctly, whether the whole list is displayed or nothing is displayed.</p>
  <p>Examples of string of characters :</p>
  <p>Example 1:</p>
  <p><code>QC4 1000 ppm ; C-191108-S-0095 ; C-191108-S-0095 ; QC4 100 ppm ; QC4 1000 ppm ; Et 500 ppm ; Et 1000 ppm ; Et 2000 ppm ;</code></p>
  <p>Example2 :</p>
  <p><code>; C-210104-S-117 2 ; C-210104-S-118 1 ; C-210104-S-118 2 ; Ref 100ppm QC4 ; Ref 1000ppm QC4 ;</code></p>
  <p>and here is my code :</p>
  <pre><code>public static (List&lt;string&gt; sample, List&lt;string&gt; reference) parse()
  {
      string imput = ReadExcel();
  
      List&lt;string&gt; sample = new List&lt;string&gt;();
      List&lt;string&gt; reference = new List&lt;string&gt;();
  
      string pattern = @&quot;C-[0-9][0-9][0-9][0-9][0-9][0-9]-S-[0-9][0-9][0-9][0-9] ;&quot;;
  
      Regex rgx = new Regex(pattern);
      Regex delim = new Regex(@&quot;\s*,\s*&quot;);
  
      foreach (string term in delim.Split(imput))
      {
          if (rgx.IsMatch(term))
          {
              sample.Add(term);
              sample.ForEach(Console.WriteLine);
          }
          else
          {
              reference.Add(term);
          }
      }
  
      return (sample, reference);
  }
  </code></pre>
  <p>I don't know how to fix it. Can you help me ?</p>
  <p>Thank you for your comprehension.</p>