title: How to use linq to group a list of strings on only certain strings
body: <p>example list of strings:</p>
  <pre class="lang-cs prettyprint-override"><code>var test = new List&lt;string&gt;{
      &quot;hdr1&quot;,&quot;abc&quot;,&quot;def&quot;,&quot;ghi&quot;,&quot;hdr2&quot;,&quot;lmn&quot;,&quot;opq&quot;,&quot;hdr3&quot;,&quot;rst&quot;,&quot;xyz&quot;
  };
  </code></pre>
  <p>I want to partition this list by <code>&quot;hdr*&quot;</code> so that each group contains elements...</p>
  <pre class="lang-none prettyprint-override"><code>&quot;hdr1&quot;,&quot;abc&quot;,&quot;def&quot;,&quot;ghi&quot;  
  &quot;hdr2&quot;,&quot;lmn&quot;,&quot;opq&quot;,  
  &quot;hdr3&quot;,&quot;rst&quot;,&quot;xyz&quot;  
  </code></pre>
  <p>I tried:</p>
  <pre class="lang-cs prettyprint-override"><code>var result = test.GroupBy(g =&gt; g.StartsWith(&quot;hdr&quot;));
  </code></pre>
  <p>but this gives me two groups</p>
  <pre class="lang-none prettyprint-override"><code>&quot;hdr1&quot;,&quot;hdr2&quot;,&quot;hdr3&quot;  
  &quot;abc&quot;,&quot;def&quot;...&quot;xyz&quot;  
  </code></pre>
  <p>What is the proper LINQ statement I should use? Let me emphasize that the strings following <code>&quot;hdr*&quot;</code> could be anything. The only thing they have in common is that they follow <code>&quot;hdr*&quot;</code>.</p>