private List<StringMatchLocation> regex(final String string, final int limit) {
        if (string == null) {
            return Collections.emptyList();
        }
        // Compile the pattern on first use
        if (pattern != null) {
            if (regexPattern == null) {
                int flags = 0;
                if (!caseSensitive) {
                    flags = flags | Pattern.CASE_INSENSITIVE;
                }
                regexPattern = Pattern.compile(pattern, flags);
            }

            final Matcher matcher = regexPattern.matcher(string);
            final List<StringMatchLocation> list = new ArrayList<>();
            for (int i = 0; i < limit && matcher.find(); i++) {
                list.add(new StringMatchLocation(matcher.start(), matcher.end() - matcher.start()));
            }
            return list;
        } else {
            return Collections.emptyList();
        }
    }
Types that will need the case of pattern to be normalised if caseSensitive is true.
stroom-index/stroom-index-lucene980/src/main/java/stroom/contentindex/StringMatcher.java