title: Java How To Parse String With Pattern [key1]value1[key2]value2[key3]value3
body: <p>I have a key-value string with the following pattern in my Java program:</p>
  
  <pre><code>[key1]value1[key2]value2[key3]value3
  </code></pre>
  
  <p>where <code>key</code>s and <code>value</code>s are Strings.</p>
  
  <p>How can I parse this string and take key-value pairs in to a Map?</p>
  
  <p>Firstly, by splitting the string with a regex, it should give the values and then parsing the string with the same regex could provide the keys. Coming up with this regex is the main issue of mine as I've hardly used regex.</p>