public Set<String> findMatches(String text, Pattern pattern) {
        Set<String> results = null;
        Matcher matcher = pattern.matcher(text);
        if (matcher.find()) {
            results = new HashSet<>();
            results.add(matcher.group(0));
            while (matcher.find()) {
                results.add(matcher.group(0));
            }
        }
        return results;
    }
finds matching sub groups in text

@param text    text containing interesting sub strings
@param pattern pattern to find sub strings
@return set of sub strings if any found, or null if none found
tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/ner/regex/RegexNERecogniser.java