Email and URL regular expressions. 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 provide two types of regular expressions for verifying the Email regular expression and URL regular expression, 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"Valid email format";
Echo"
";
Echo"
";
}
Else
{
Echo "invalid email format ";
Echo"
";
Echo"
";
}
}
// 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"Valid url format";
Echo"
";
Echo"
";
}
Else
{
Echo "invalid url format ";
Echo"
";
Echo"
";
}
}
...