title: parse key: value pair with regular expressions
body: <p>I have a service which I hit gives response back in below format <code>key: value</code> and I want to extract key/value pair from it and load it in a map.</p>
  
  <pre><code>state: UP flag: 9 time: 02:29:09.111782 highest_id: num_users: 0 num_records: 0
  </code></pre>
  
  <p>So I am using regular expression to parse this and extract key/value pair from it.</p>
  
  <pre><code>private static final Pattern PATTERN = Pattern.compile("\\s*(\\S+)\\s*:\\s*(\\S+)");
  
  String response = restTemplate.getForObject(url, String.class);
  Matcher m = PATTERN.matcher(response);
  while (m.find()) {
      String key = m.group(1).trim();
      String value = m.group(2).trim();
      // load key/value in a map
  }
  </code></pre>
  
  <p>Now problem with above regular expression is for above data - it takes <code>highest_id</code> as key but it takes <code>num_users: 0</code> as it's value which is wrong. In this case it should take <code>highest_id</code> as key and value should be empty string or null since there is nothing after <code>:</code> for that key and next key should be <code>num_users</code> and value should be <code>0</code>.</p>
  
  <p>What is wrong with my regular expression?</p>