public static Predicate<String> createRegexPredicate(final String userInput) {
        LOGGER.trace("Creating regex predicate for {}", userInput);
        Pattern pattern;
        try {
            pattern = Pattern.compile(userInput, Pattern.CASE_INSENSITIVE);
        } catch (Exception e) {
            LOGGER.trace(() ->
                    LogUtil.message("Invalid pattern {}, due to {}", userInput, e.getMessage()));
            // Bad pattern, can't really raise an exception as the user may have just mis-typed
            // so just return a false predicate
            return str -> false;
        }

        final Predicate<String> predicate;
        try {
            predicate = pattern.asPredicate();
        } catch (Exception e) {
            LOGGER.trace(() ->
                    LogUtil.message("Error converting pattern {} to predicate, due to {}", userInput, e.getMessage()));
            return str -> false;
        }
        return toNullSafePredicate(false, predicate);
    }
For a given user input this method will return a function that can evaluate a string to see how
good the match is. The quality of the match is determined by the length of the matched region
(shorter == better) and its distance from the start of the string (closer == better).
stroom-query/stroom-query-common/src/main/java/stroom/query/common/v2/StringPredicateFactory.java