title: Plucking JSON IDs out with Java Regex/Matcher API
body: <p>I have a Java method that will receive a minified JSON string resembling:</p>
  
  <pre><code>{
    "fizz": {
      "_id": "6"
    }
  }
  {
    "foo": "bar"
  }
  ... (same two above objects repeated but with different values)
  </code></pre>
  
  <p>Hence minified the string would be <code>{"fizz":{"_id":"6"}}</code>. The string will be different each time the method is called (obviously) but it will adhere to the following format:</p>
  
  <pre><code>"CHUNK" Consists of:
  {"&lt;ANYTHING&gt;":{"_id":"&lt;SOME_NUMBER&gt;"}}{&lt;ANY_JSON_OBJECT&gt;}
  </code></pre>
  
  <p>So as another example the method might receive the following string as input (not minifying it so as to make the example clearer):</p>
  
  <pre><code>{
    "fizz": {
      "_id": "6"
    }
  }
  {
    "foo": "bar"
  }
  
  
  {
    "swarm": {
      "_id": "18"
    }
  }
  {
    "whistle": "feather",
    "saywhat": true
  }
  
  
  {
    "beef": {
      "_id": "23"
    }
  }
  {
    "active": "NO"
  }
  </code></pre>
  
  <p>I need to extract a list of all the <code>_id</code> string values in the given JSON, so in the example above, I'd want to end up with a <code>List&lt;String&gt;</code> containing "6", "18" and "23". My best attempt:</p>
  
  <pre><code>public List&lt;String&gt; extractIds(String json) {
      Pattern pattern = Pattern.compile("\"_id\":.*");
      Matcher matcher = pattern.matcher(json);
      List&lt;String&gt; ids = new ArrayList&lt;&gt;();
  
      while(matcher.find()) {
        ids.add("???");
      }
  
      return ids;
  }
  </code></pre>
  
  <p>But I'm not sure whether my regex is jacked up and/or how to use the Matcher API to extract the next extracted ID in the group.</p>
  
  <p>Any ideas where I'm going awry?</p>