$re = '/\b"{0,1}[A-Z0-9_][A-Z0-9._%+-]*[A-Z0-9_]\@(?![. \-])(([A-Z0-9-]+\.)+[A-Z]{2,8}|\[{0,1}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\]{0,1})\b/i';
$str = 'invalid formats
cf+2@3465456rteyaesrgrdsfgsdfg@thefloow.com
@@@
Leading dot in address eg .cf@thefloow.com
Trailing dot in address eg cf+.@thefloow.com
Multiple dots eg cf+..1@thefloow.com
Leading dash in front of domain eg cf@-thefloow.com
invalid top level domain names eg cf@thefloow.web
Multiple dots in the domain portion cf@thefloow..com
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 allowe
email..email@domain.com Multiple dots
あいうえお@domain.com Unicode char as address
email@domain.com (Joe Smith) Text followed email is not allowed
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
plainaddress
#@%^%#$@#$@#.com
@example.com
Joe Smith <email@example.com>
email.example.com
email@example@example.com
.email@example.com
email.@example.com
email..email@example.com
あいうえお@example.com
email@example.com (Joe Smith)
email@example
email@-example.com
email@example.web
email@111.222.333.44444
email@111.222.333.244
email@01.222.233.244
email@example..com
Abc..123@example.com
“(),:;<>[\\]@example.com
just"not"right@example.com
this\\ is"really"not\\allowed@example.com
valid formats
ip address as domain name eg cf@192.168.0.1
quoted strings eg "cf"@thefloow.com
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
email@example.com
firstname.lastname@example.com
email@subdomain.example.com
firstname+lastname@example.com
email@123.123.123.0
email@[123.123.0.123]
email@123.0.123.123
email@[0.123.123.123]
“email”@example.com
1234567890@example.com
email@example-one.com
_______@example.com
email@example.name
email@example.museum
email@example.co.jp
3465456rteyaesrgrdsfgsdfg@thefloow.com
firstname-lastname@example.com
much.“more\\ unusual”@example.com
very.unusual.“@”.unusual.com@example.com
very.“(),:;<>[]”.VERY.“very@\\\\ "very”.unusual@strange.example.com';
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