title: How to tokenize Java String with nested square brackets?
body: <p>I have a string I would like to put into an ArrayList of Strings. The string is basically a JSONObject so I might just be using the wrong methods.</p>
  
  <p>The way the string looks is:</p>
  
  <pre><code>String all = "{"users":
  [
   [{"login":"username1"},{"password":"test1"},{"index":"1"}],
   [{"login":"username2"},{"password":"test2"},{"index":"2"}]
  ]}";
  </code></pre>
  
  <p>All I want is the JSONObject values so my pattern gives me this String:</p>
  
  <pre><code>String part = "[
                  [{"login":"username1"},{"password":"test1"},{"index":"1"}],
                  [{"login":"username2"},{"password":"test2"},{"index":"2"}]
                 ]";
  </code></pre>
  
  <p>This is what I want:</p>
  
  <pre><code>user[0] = "[{"login":"username1"},{"password":"test1"},{"index":"1"}]";
  user[1] = "[{"login":"username2"},{"password":"test2"},{"index":"2"}]";
  </code></pre>
  
  <p>When I try to group everything in between the inner [ ] it just returns everything in the outer [ ].</p>
  
  <p>I have tried:</p>
  
  <pre><code>String[] user = new String[20];
  Pattern p = Pattern.compile("(\\[\\{.*\\}\\])");
  Matcher m = p.matcher(part);
  while(m.find()){
      user = m.group().split("\\],\\[");
  }
  </code></pre>
  
  <p>This approach gets rid of the ],[ which I'm using as a delimiter.</p>