the source of org.springframework.boot.autoconfigure.condition.OnPropertyCondition.Spec#isMatch is simple value equals

private boolean isMatch(String value, String requiredValue) {
    if (StringUtils.hasLength(requiredValue)) {
        return requiredValue.equalsIgnoreCase(value);
    }
    return !"false".equalsIgnoreCase(value);
}

but sometimes set value is not a fixed value

like this

@ConditionalOnProperty(name = "token", havingValue = "\w{4}-\w{4}-\w{4}-\w{4}")

Comment From: wilkinsona

Thanks for the suggestion, but I don't think we should support this in the condition itself. To do so we'd either have to provide another attribute that was treated as a regular expression or detect that the value of havingValue was a regular expression. The former would complicate the API as users would have to understand the difference between havingValue and the new attribute and only use one or the other. The latter would hurt performance as we'd have to perform the detection for every usage of @ConditionalOnProperty.

In my opinion, it would be better to allow the value to be bound as-is and then validate that it matches a required pattern in your @ConfigurationProperties class. Alternatively, you could use a custom type to enforce the requirement and register a converter with the conversion service to perform the string to custom type conversion.

You haven't described your usecase in detail, but it you really want to perform a regex match in the condition itself, you could implement your own condition or perhaps even use @ConditionalOnExpression.