regex

The regular expression that an EmailAddress should match.

Based on RFC-5322, the underlying pattern is ^[A-Za-z]+(?:\.[A-Za-z]+)*@(?:[A-Za-z][A-Za-z\d-]{0,61}[A-Za-z\d]\.)*[A-Za-z][A-Za-z\d-]{0,61}[A-Za-z\d]$.

Here's the explanation associated to each symbol used in this regular expression:

  • ^ Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.

  • [] Character set. Match any character in the set.

  • A-Z Range. Matches a character in the range "A" to "Z" (char code 65 to 90). Case-sensitive.

  • a-z Range. Matches a character in the range "a" to "z" (char code 97 to 122). Case-sensitive.

  • + Quantifier. Match 1 or more of the preceding token.

  • (?:) Non-capturing group. Groups multiple tokens together without creating a capture group.

  • \. Escaped character. Matches a "." character (char code 46).

  • * Quantifier. Match 0 or more of the preceding token.

  • @ Character. Match a "@" character (char code 64).

  • \d Digit. Matches any digit character (0-9).

  • - Character. Matches a "-" character (char code 45).

  • {0,61} Quantifier. Match between 0 and 61 of the preceding token.

  • $ End. Matches the end of the string, or the end of a line if the multiline flag (m) is enabled.

Here's an example of calling this property from Kotlin code:

println(EmailAddress.regex) // ^[A-Za-z]+(?:\.[A-Za-z]+)*@(?:[A-Za-z][A-Za-z\d-]{0,61}[A-Za-z\d]\.)*[A-Za-z][A-Za-z\d-]{0,61}[A-Za-z\d]$

The Regex type being unavailable on Java, this property is not available for this language.