title: How to separate a string that can be dynamic using certain words
body: <p>I am trying to separate a certain string based on certain keys and add them to a map in key value pairs. The keys can change position. I'm new to regex and would like some assistance in completing it.</p>
  
  <p>I have a string <code>"key1=valueforkey1&amp;key2=valueforkey2"</code>. This string can also change to <code>"key2=valueforkey2&amp;key1=valueforkey1"</code>. </p>
  
  <p>My regex works for the above and separates the keys and values correctly.</p>
  
  <p>It doesnt work when the value includes "=" before the key. </p>
  
  <p>For example </p>
  
  <pre><code>"key1=valueforkey1=&amp;key2=valueforkey2"
  </code></pre>
  
  <p>or </p>
  
  <pre><code>"key1=valueforkey1==&amp;key2=valueforkey2".
  </code></pre>
  
  <p>My map will contain </p>
  
  <pre><code>map("key1", "valueforkey1") 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>map("key2", "valueforkey2")
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>map("key1", "valueforkey1==") 
  
  map("key2", "valueforkey2") 
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>String delimiter = "[= &amp; ?]+";
  String[] split = text.split(delimiter );
  for (int i=0; i&lt;split.length; i+=2) {
      maps.put(split[i], split[i+1]);
  }
  
  </code></pre>
  
  <p>I expect to separate the string and add them in key value pairs in a map.</p>
  
  <pre><code>map("key1", "valueforkey1") or
  
  map("key1", "valueforkey1=") or
  
  map("key1", "valueforkey1==")
  </code></pre>
  
  <p>and </p>
  
  <pre><code>map("key2", "valueforkey2") or
  
  map("key2", "valueforkey2=") or
  
  map("key2", "valueforkey2==")
  </code></pre>