title: Creating string array using Regex.Split
body: <p>Alright, I'm warning you in advance, my understanding of Regular Expressions is extremely limited (I've tried my best to learn them over the years, but to be honest, I think they just frighten me.)</p>
  
  <p>Let's say I have the following string:</p>
  
  <pre><code>string keyValues = "CustomerId=1||OrderId=12||UserId=a1dcd568-f129-419b-b51e-be2dbb67de0f"
  </code></pre>
  
  <p>This string represents key-value pairs, delimited by a user-defined string (in this case <code>||</code>) (e.g. <code>key1=value1||key2=value2</code>). I am trying to extract the keys out of this string and store them in an array. That array would look like this:</p>
  
  <pre><code>{"CustomerId", "OrderId", "UserId"}
  </code></pre>
  
  <p>The best option I can think of is to use regular expressions (If someone has a better solution, please share). Here's what I'm trying to do:</p>
  
  <pre><code>string delimiter = "||";
  string[] keys = Regex.Split(keyValues, "=.*" + delimiter);
  </code></pre>
  
  <p>I may be wrong, but the way I understand it, that regular expression is supposed to find a string that starts with <code>=</code> and ends with <code>delimiter</code>, with any number of any characters in between. Which would split the string at those positions, leaving me with the original keys, but instead, my keys array looks like this:</p>
  
  <pre><code>{"", "C", "u", "s", "t", "o", "m", "e", "r", "I", "d", "", "", ...}
  </code></pre>
  
  <p>As you can see, the <code>=value||</code> part is stripped away. Can anyone tell me what I'm doing wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>In my case, the delimiter <code>||</code> is a variable. I didn't mention this only because I thought I would be able to replace any references to <code>||</code> with <code>delimiter</code>. From the majority of the answers given, I now see that that is an important detail.</p>