code: public static void setIndex(Matcher matcher, int idx) {
          int count = getCount(matcher);
          if (idx < -count || idx >= count) {
              throw new IndexOutOfBoundsException("index is out of range " + (-count) + ".." + (count - 1) + " (index = " + idx + ")");
          }
          if (idx == 0) {
              matcher.reset();
          } else if (idx > 0) {
              matcher.reset();
              for (int i = 0; i < idx; i++) {
                  matcher.find();
              }
          } else if (idx < 0) {
              matcher.reset();
              idx += getCount(matcher);
              for (int i = 0; i < idx; i++) {
                  matcher.find();
              }
          }
      }
docs: Set the position of the given Matcher to the given index.
  
  @param matcher a Matcher
  @param idx     the index number
  @since 1.0