void () { char nextChar; if (myCursor == myTemplate.length()) throw new IllegalArgumentException("Illegal group reference: group index is missing"); nextChar = myTemplate.charAt(myCursor++); String group; if (nextChar == '{') { StringBuilder gsb = new StringBuilder(); while (myCursor < myTemplate.length()) { nextChar = myTemplate.charAt(myCursor); if (isLatinLetter(nextChar) || isDigit(nextChar)) { gsb.append(nextChar); myCursor++; } else { break; } } if (gsb.length() == 0) throw new IllegalArgumentException("named capturing group has 0 length name"); if (nextChar != '}') throw new IllegalArgumentException("named capturing group is missing trailing '}'"); String gname = gsb.toString(); if (isDigit(gname.charAt(0))) { throw new IllegalArgumentException("capturing group name {" + gname + "} starts with digit character"); } myCursor++; group = myMatcher.group(gname); }