Here, the e-mail Regular Expression and URL regular expression provide two types of Regular Expressions for Email Regular Expression and URL Regular Expression verification, which are very practical, the Regular Expression of email can obtain all the email addresses in the content, and the regular expression of url addresses is the same. You can save and extract all the URLs starting with http in the content.
Email and url Regular Expressions
Here we provide two types of Regular Expressions for email Regular Expressions and url regular expressions, which are very practical. The regular expressions for email can obtain all the email addresses in the content, the same is true for url address regular expressions. You can save and extract all the URLs starting with http in the content.
*/
$ Str_arr = array (
"Mymail@bKjia.c0m ",
"My_mail@bKjia.c0m ",
"My-mail@bKjia.c0m ",
"My.mail@site.com.cn ",
"Mymail@site.com.ccoomm ",
"Mymail@site.cn ",
"Mymail @ lsite.com ",
"Mymail @ site ",
"Mymail@bKjia.c0m ",
"My2007@bKjia.c0m ",
"163mail_for-me777@bKjia.c0m ",
);
$ Patt_email = "/^ [_ a-za-z0-9-] + @ ([0-9a-z] [0-9a-z-] +.) + [a-z] {2, 4} $ /";
Foreach ($ str_arr as $ str)
{
Echo "string '$ str': yes ";
If (preg_match ($ patt_email, $ str ))
{
Echo "<B> valid email format </B> ";
Echo "<br> ";
Echo "<br> ";
}
Else
{
Echo "invalid email format ";
Echo "<br> ";
Echo "<br> ";
}
}
// 17. url regular expression.
$ Str_arr = array (
Http://www.bKjia. c0m ",
"Www. bKjia. c0m ",
Http://www.bKjia. c0m/abc/123.html ",
"// BKjia. c0m ",
": Www. bKjia. c0m"
);
$ Patt_url = "/^ (http ://)? [A-za-z0-9] + (. [a-za-z0-9] +) *. + $ /";
Foreach ($ str_arr as $ str)
{
Echo "string '$ str': yes ";
If (preg_match ($ patt_url, $ str ))
{
Echo "<B> legal url format </B> ";
Echo "<br> ";
Echo "<br> ";
}
Else
{
Echo "invalid url format ";
Echo "<br> ";
Echo "<br> ";
}
}