title: out of bounds exception for java Matcher
body: <p>Hi I have the string <code>"id:2 CAT-id:9-101"</code>.  I want to extract the id values, 2 and 9, from this string.  I have read <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#group(int)" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#group(int)</a></p>
  
  <p>and have tried this code but it throws an exception when trying to extract the 9:</p>
  
  <pre><code>Pattern p = Pattern.compile("id:([0-9]+)");
  Matcher m = p.matcher("id:2 CAT-id:9-101");
  
  ArrayList&lt;Integer&gt; ids = new ArrayList&lt;Integer&gt;();
  int index = 1;
  while(m.find()) {
      String match = m.group(index);
  int id = Integer.parseInt(match);
  ids.add(id);
  index++;
  }
  </code></pre>
  
  <p>I am also confused when reading <a href="http://docs.oracle.com/javase/tutorial/essential/regex/groups.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/essential/regex/groups.html</a>; am I supposed to use backreferences here instead to get the ids?  I tried that later and m.find() always returned false when I changed the regex to <code>"id:([0-9]+)\\$1"</code></p>