PHP regular matching email code is analyzed in more detail. I hope friends who have questions about this can take a look.
CODE:
1. <?php
2. if (ereg(“/^[az]([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[- _]?[a-z0-9]+)+[.][az]{2,3}([.][az]{2})?$/i; ”,$email)){
3. echo “Your email address is correct!”;}
4.else{
5. echo “Please try again!”;
6. }
7. ?>
The international domain name format is as follows:
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. However, "-" cannot be included at the beginning or end, and "-" 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.).
/^[az]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9 ]+)+[.][az]{2,3}([.][az]{2})?$/i;
/content/i forms a case-insensitive regular expression;
^ match starts
$ End of match
[az] 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 preceding characters.
[a-z0-9]* matches 0 or more English letters or numbers
[-_]? Matches 0 or 1 "-", because "-" cannot appear consecutively
[a-z0-9]+ matches 1 or more English letters or numbers, because "-" cannot be used as the end
@ There must be one @
([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
[az]{2,3} matches 2 to 3 English letters, usually com or net, etc.
([.][az]{2})? Matches 0 or 1 [.][az]{2} (such as .cn, etc.) I don’t know if the last part of .com.cn is usually Two digits, if not, please change {2} to {number of starting words, number of ending words}
Perfect E-Mail regular expression, with detailed explanation, please help test it! 2. Extract the email in the string:
<?php
function getEmail($str) {
$pattern = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0 -9]+)+[.][az]{2,3}([.][az]{2})?/i";
preg_match_all($pattern,$str,$emailArr);
return $emailArr[0];
}
$emailstr = " [email protected] I'm not from Mivi, so I opened the iid mailing list: [email protected] and [email protected] ;.;;, [email protected],fu-1999@ sina.com ";
$emailArr = getEmail($emailstr);
echo "<pre>";
print_r($emailArr);
echo "</pre>";
?>
Print as follows:
Array
(
[0] =>[email protected]
[1] =>[email protected]
[2] =>[email protected]
[3] =>[email protected]
[4] =>[email protected]
)
3. Comparison: The regex in the second one does not have the ^ and $ in the first one;