code: public static boolean isValidRegex(final String pattern) {
          try {
              if (pattern != null) {
                  Pattern.compile(pattern);
                  return true;
              }
          } catch (final PatternSyntaxException exception) {
              LOGGER.debug("Pattern [{}] is not a valid regex.", pattern);
          }
          return false;
      }
docs: 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