php regular matching email code, the analysis is also more detailed. I hope friends who have questions in this regard can take a look at The format of the international domain name is as follows:
CODE:
1. < ?php
2. if (ereg(“/^[a-z]([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[ a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?$/i; ”,$email)){
3. echo “ Your email address is correct!";}
4. else{
5. echo "Please try again!";
6. }
7. ?>
The domain name is composed of any combination of specific character sets, English letters, numbers and "-" (i.e. hyphens or minus signs) in various countries, but it cannot contain "-" at the beginning or at the end. ", "-" cannot appear continuously. Letters in domain names are not case-sensitive. The domain name can be up to 60 bytes long (including suffixes .com, .net, .org, etc.).
/^[a-z]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a- z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?$/i;
/content/i constitutes a case-insensitive regular expression Formula;
^ Match start
$ Match end
[a-z] E-Mail prefix must start with an English letter
([a-z0-9]*[-_]?[a- z0-9]+)* matches _a_2, aaa11, _1_a_2, but does not match a1_, aaff_33a_, a__aa. If it is a null character, it will also match. * means 0 or more.
* represents 0 or more previous characters.
[a-z0-9]* matches 0 or more English letters or numbers
[-_]? matches 0 or 1 "- ", because "-" cannot appear continuously
[a-z0-9]+ matches one or more English letters or numbers, because "-" cannot be the end
@ There must be @
([a-z0-9]*[-_]?[a-z0-9]+)+ see above ([a-z0-9]*[-_]?[a-z0-9]+) *Explanation, but it cannot be empty, + means one or more.
[.] Treat special characters (.) as ordinary characters
[a-z]{2,3} matches 2 to 3 English letters, usually com or net, etc.
([.][ a-z]{2})? Match 0 or 1 [.][a-z]{2} (such as .cn, etc.) I don’t know if the last part of .com.cn is usually two digits. If not, please Modify {2} to {starting word number, ending word number}
Perfect E-Mail regular expression, with detailed explanation, please help test it! 2. Extract email from the string:
function getEmail($str) {
$pattern = "/([a-z0-9]*[-_.]?[ a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][ a-z]{2})?/i";
preg_match_all($pattern,$str,$emailArr);
return $emailArr[0];
}
$emailstr = "9999@qq .com.cn If I am not from Mivi, I will open an iid mailing list: fuyongjie@163.com and hh@qq.com;, fuyongjie.100@yahoo.com, fu-1999@sina.com";
$emailArr = getEmail($emailstr);
echo "";<br>print_r($emailArr);<br>echo "
";
?>
Print as follows:
Array
(
[0] =>9999@qq.com.cn
[1] =>fuyongjie@163.com
[2] => ;hh@qq.com
[3] =>fuyongjie.100@yahoo.com
[4] =>fu-1999@sina.com
)
3. Comparison: No. The regular expression in 2 no longer contains the first ^ and $;