Use regexp pattern groups:
  Pattern pattern = Pattern.compile("(\d+)?..(\d+)?");
  Matcher matcher = pattern.match(inputString);
  if (matcher.match()) {
    // Use matcher.group(1) and matcher.group(2)
  }