Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?<local>[a-zA-Z0-9\.!#$%&'*\-\/=?^_`{|}~"]+)(?:\.)?(?<routing>[a-zA-Z0-9\.!#$%&'*\-\/=?^_`{|}~+"]*)(?:@)(?<domain>(?:[a-zA-Z0-9\-[\]]*)(?:\.)(?:[a-zA-Z0-9\-[\]\.]*))$
/
gm

Description

This regex enforces the correct basic structure whilst only allowing permitted characters (RFC822) in both the local and domain parts. It permits + routing made popular by Gmail and allows for the + group to identified as routing. It allows all but the most extreme of valid email addresses i.e. "@" at symbols contained in quotes. A cautionary note, just because RFC permits these characters you own mail server may not accept them all.

Submitted by anonymous - 6 years ago