@NotNull
    private static Predicate<String> createCamelCaseWordBoundaryPredicate(
            final String userInput) {

        // Has some uppercase so use word boundaries
        // An upper case letter means the start of a word
        // a lower case letter means the continuation of a word

        final StringBuilder patternBuilder = new StringBuilder();
        for (int i = 0; i < userInput.length(); i++) {
            char chr = userInput.charAt(i);

            if (Character.isUpperCase(chr)) {
                if (i == 0) {
                    // First letter so is either preceded by ^ or
                    // by the end of the previous word
                    patternBuilder
                            .append("(?:^|[a-z0-9]") // non-capturing, assume numbers part of prev word
                            .append(")");
                } else {
                    // Not the first letter so need the end of the previous word
                    // and a word separator
                    patternBuilder
                            .append("[a-z0-9]")
                            .append("*");
                }
                // Start of a word
            }

            if (Character.isLetterOrDigit(chr)) {
                patternBuilder.append(chr);
            } else {
                // Might be a special char so escape it
                patternBuilder.append(Pattern.quote(String.valueOf(chr)));
            }
        }
        final Pattern pattern = Pattern.compile(patternBuilder.toString());
        LOGGER.trace("Using (C|c)amelCase separated pattern: {}", pattern);
        return toNullSafePredicate(false, pattern.asPredicate());
    }
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