public static Validator createRegexMatchingValidator()

in src/main/java/org/apache/nifi/processor/util/StandardValidators.java [613:649]


    public static Validator createRegexMatchingValidator(final Pattern pattern, final boolean evaluateExpressions, final String validationMessage) {
        return new Validator() {
            @Override
            public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
                String value = input;
                if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
                    if (evaluateExpressions) {
                        try {
                            value = context.newPropertyValue(input).evaluateAttributeExpressions().getValue();
                        } catch (final Exception e) {
                            return new ValidationResult.Builder()
                                    .subject(subject)
                                    .input(input)
                                    .valid(false)
                                .explanation("Failed to evaluate the Attribute Expression Language due to " + e)
                                    .build();
                        }
                    } else {
                        return new ValidationResult.Builder()
                                .subject(subject)
                                .input(input)
                                .explanation("Expression Language Present")
                                .valid(true)
                                .build();
                    }
                }

                final boolean matches = value != null && pattern.matcher(value).matches();
                return new ValidationResult.Builder()
                        .input(input)
                        .subject(subject)
                        .valid(matches)
                        .explanation(matches ? null : validationMessage)
                        .build();
            }
        };
    }