public String getKey(String selector, String template) {
        String season = null;
        int offset = 5;
        if (!selector.startsWith("YEAR ")) {
            season = selector.substring(0, 6);
            offset = 7;
        }
        int year = Integer.parseInt(selector.substring(offset));
        Matcher matcher = turnPattern.matcher(template);
        while (matcher.find()) {
            if (matcher.group(6) != null) {
                // must be a single year, not a range
                if (compare(matcher.group(5), Integer.parseInt(matcher.group(6)),
                            season, year) == 0) {
                    return matcher.group(0);
                }
            } else {
                // must be a range
                if (compare(matcher.group(1), Integer.parseInt(matcher.group(2)), season, year) <= 0
                    && compare(matcher.group(3), Integer.parseInt(matcher.group(4)), season, year) >= 0) {
                    return matcher.group(0);
                }
            }
        }
        return selector;
    }