private TopicPartitionFilter parseRuleSpec(String ruleSpec) throws TerseException, RuntimeException {
        Matcher matcher = TOPIC_PARTITION_PATTERN.matcher(ruleSpec);

        if (!matcher.matches())
            throw new TerseException("Invalid rule specification: " + ruleSpec);

        IntFunction<String> group = (int g) -> (matcher.group(g) != null && !matcher.group(g).isEmpty()) ? matcher.group(g) : null;

        IncludeList topicFilter = group.apply(1) != null ? new IncludeList(group.apply(1)) : new IncludeList(".*");

        PartitionFilter partitionFilter;

        if (group.apply(2) != null) {
            partitionFilter = new UniquePartitionFilter(Integer.parseInt(group.apply(2)));
        } else {
            int lowerRange = group.apply(3) != null ? Integer.parseInt(group.apply(3)) : 0;
            int upperRange = group.apply(4) != null ? Integer.parseInt(group.apply(4)) : Integer.MAX_VALUE;

            partitionFilter = new PartitionRangeFilter(lowerRange, upperRange);
        }

        return new TopicPartitionFilter.TopicFilterAndPartitionFilter(topicFilter, partitionFilter);
    }
Return the partition infos. Filter them with topicPartitionFilter.
tools/src/main/java/org/apache/kafka/tools/GetOffsetShell.java