Hibernate 验证器为@Email 使用的正则表达式模式到底是什么?

What precisely is the regex pattern that Hibernate validator employes for @Email?

版本:

hibernate-validator: 6.2.0.Final (from mvnrepository.com)

如果需要,您可以阅读relevant docs at jboss.org

我发现 Hibernate 验证器(通过 @Email 注释)开箱即用地支持验证电子邮件地址(即,对于应该包含有效电子邮件的字符串地址)。

问题:有人知道 Hibernate Validator 6.2 用于 @Email 验证的默认正则表达式吗?

来自hibernate-validator source code

  • Checks that a given character sequence (e.g. string) is a well-formed email address.
  • The specification of a valid email can be found in RFC 2822 and one can come up with a regular expression matching all valid email addresses as per specification. However, as this article discusses it is not necessarily practical to implement a 100% compliant email validator. This implementation is a trade-off trying to match most email while ignoring for example emails with double quotes or comments.
private static final int MAX_LOCAL_PART_LENGTH = 64;

private static final String LOCAL_PART_ATOM = "[a-z0-9!#$%&'*+/=?^_`{|}~\u0080-\uFFFF-]";
private static final String LOCAL_PART_INSIDE_QUOTES_ATOM = "(?:[a-z0-9!#$%&'*.(),<>\[\]:;  @+/=?^_`{|}~\u0080-\uFFFF-]|\\\\|\\\\")";
/**
 * Regular expression for the local part of an email address (everything before '@')
 */
private static final Pattern LOCAL_PART_PATTERN = Pattern.compile(
        "(?:" + LOCAL_PART_ATOM + "+|\"" + LOCAL_PART_INSIDE_QUOTES_ATOM + "+\")" +
                "(?:\." + "(?:" + LOCAL_PART_ATOM + "+|\"" + LOCAL_PART_INSIDE_QUOTES_ATOM + "+\")" + ")*", CASE_INSENSITIVE
);

另见 the regex for the domain part