public static Validator validRegex() {
    return (name, val) -> {
      if (!(val instanceof List)) {
        throw new IllegalArgumentException("validator should only be used with "
            + "LIST of STRING defs");
      }

      final StringBuilder regexBuilder = new StringBuilder();
      for (Object item : (List)val) {
        if (!(item instanceof String)) {
          throw new IllegalArgumentException("validator should only be used with "
              + "LIST of STRING defs");
        }

        if (regexBuilder.length() > 0) {
          regexBuilder.append("|");
        }

        regexBuilder.append((String)item);
      }

      try {
        Pattern.compile(regexBuilder.toString());
      } catch (final Exception e) {
        throw new ConfigException(name, val, "Not valid regular expression: " + e.getMessage());
      }
    };
  }
@Test
  public void shouldNotThrowOnValidRegex() {
    // Given
    final Validator validator = ConfigValidators.validRegex();

    // When:
    validator.ensureValid("propName", Collections.singletonList("prefix_.*"));

    // Then: did not throw.
  }