public static boolean isValidRegex(final String pattern) {
        try {
            if (StringUtils.isNotBlank(pattern)) {
                Pattern.compile(pattern);
                return true;
            }
        } catch (final PatternSyntaxException exception) {
            LOGGER.debug("Pattern [{}] is not a valid regex.", pattern);
        }
        return false;
    }
Check to see if the specified pattern is a valid regular expression.

@param pattern the pattern
@return whether this is a valid regex or not
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/RegexUtils.java