$re = '/(?<![-!#$%&\'*+\/=?^_`{|}~@."\]\\\\a-zA-Zа-яА-ЯёЁ\d]) #граница
(?:
[-!#$%&\'*\/=?^_`{|}~a-zA-Z\d\+]+
| [-!#$%&\'*\/=?^_`{|}~а-яА-ЯёЁ\d\+]+
| "(?:(?:[^"\\\\]|\\\\.)+)"
)
(?:
[.+]
(?:
#просмотр вперёд с обратной ссылкой запрещает "откат" (backtrace) в случае неудачи и значительно ускоряет работу цикла внутри цикла
(?=([-!#$%&\'*\/=?^_`{|}~a-zA-Z\d]+))\1
| (?=([-!#$%&\'*\/=?^_`{|}~а-яА-ЯёЁ\d]+))\2
| "(?=((?:[^"\\\\]|\\\\.)+))\3"
)
)*
@
(?:
(?:
(?: #домены 2-го и последующих уровней
(?!-)
(?:
(?:[a-zA-Z\d]|-(?!-)){1,63}
| (?:[а-яА-ЯёЁ\d]|-(?!-)){1,63}
)
(?<!-)
\.
)+
(?: #домен 1-го уровня
[a-zA-Z]{2,63}
| [а-яА-ЯёЁ]{2,63}
)
)
(?![a-zA-Zа-яА-ЯёЁ\d@]) #граница
| (?: #IPv4
(?<!\d)
(?!0+\.)
(?:1?\d\d?|2(?:[0-4]\d|5[0-5]))(?:\.(?:1?\d\d?|2(?:[0-4]\d|5[0-5]))){3}
(?!\d)
)
| \[ #IPv4 в квадратных скобках
(?:
(?<!\d)
(?!0+\.)
(?:1?\d\d?|2(?:[0-4]\d|5[0-5]))(?:\.(?:1?\d\d?|2(?:[0-4]\d|5[0-5]))){3}
(?!\d)
)
\]
)/sx';
$str = 'Valid email addresses
---------------------
ПишитеМне@ИвановИван.почта.рф
Иванов.Иван@Санкт-Петербург.онлайн
Ivanov.Иван@москва.ru
Ivanov.Иван+facebook@москва.ru
c++@test.com
prettyandsimple@example.com
very.common@example.com
disposable.style.email.with+symbol@example.com
other.email-with-dash@example.com
x@example.com (one-letter local part)
"much.more unusual"@example.com
"very.unusual.@.unusual.com"@example.com
"very.(),:;<>[]\\".VERY.\\"very@\\\\ \\"very\\".unusual"@strange.example.com
example-indeed@strange-example.com
#!$%&\'*+-/=?^_`{}|~@example.org
"()<>[]:,;@\\\\\\"!#$%&\'*+-/=?^_`{}| ~.a"@example.org
" "@example.org (space between the quotes)
example@s.solutions (see the List of Internet top-level domains)
©other.email-with-dash@example.com
?prettyandsimple@example.com
Эти email валидные только среде разработки. В продуктивной среде такие email пользователи применять не могут и поэтому считаются невалидными:
* admin@mailserver1 (local domain name with no TLD)
* example@localhost (sent from localhost)
* user@com
* user@localserver
* user@[IPv6:2001:db8::1]
Valid Email address Reason
--------------------------
email@domain.com Valid email
firstname.lastname@domain.com Email contains dot in the address field
email@subdomain.domain.com Email contains dot with subdomain
firstname+lastname@domain.com Plus sign is considered valid character
email@123.123.123.123 Domain is valid IP address
email@[123.123.123.123] Square bracket around IP address is considered valid
"email"@domain.com Quotes around email is considered valid
1234567890@domain.com Digits in address are valid
email@domain-one.com Dash in domain name is valid
_______@domain.com Underscore in the address field is valid
email@domain.name .name is valid Top Level Domain name
email@domain.co.jp Dot in Top Level Domain name also considered valid (use co.jp as example here)
firstname-lastname@domain.com Dash in address field is valid
Invalid Email address Reason
------------------------------
plainaddress Missing @ sign and domain
#@%^%#$@#$@#.com Garbage
@domain.com Missing username
Joe Smith <email@domain.com> Encoded html within email is invalid
email.domain.com Missing @
email@domain@domain.com Two @ sign
.email@domain.com Leading dot in address is not allowed
email.@domain.com Trailing dot in address is not allowed
email..email@domain.com Multiple dots
あいうえお@domain.com Unicode char as address
email@domain Missing top level domain (.com/.net/.org/etc)
email@-domain.com Leading dash in front of domain is invalid
email@domain.web .web is not a valid top level domain
email@111.222.333.44444 Invalid IP format
email@domain..com Multiple dot in the domain portion is invalid
Abc.example.com (no @ character)
A@b@c@example.com (only one @ is allowed outside quotation marks)
a"b(c)d,e:f;g<h>i[j\\k]l@example.com (none of the special characters in this local part are allowed outside quotation marks)
just"not"right@example.com (quoted strings must be dot separated or the only element making up the local part)
this is"not\\allowed@example.com (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a backslash)
this\\ still\\"not\\\\allowed@example.com (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes)
john..doe@example.com (double dot before @)
with caveat: Gmail lets this through, Email address#Local-part the dots altogether
john.doe@example..com (double dot after @)
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php