Email regular expression and URL regular expression Here are two regular expressions for email regular expression and URL regular expression verification, which are very practical. The regular expression for email can get all the email addresses in the content, and the same is true for URL address regular expressions. You can get all the email addresses in the content. Save and extract all URL addresses starting with http.
email regular expression and url regular expression
Here are two regular expressions for email regular expression and url regular expression verification, which are very practical. The regular expression for email can get all the email addresses in the content, and the same goes for the url address regular expression, which can be used to get all the email addresses in the content. Save and extract all URL addresses starting with http.
*/
$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 "Legitimate email format";
echo "
";
echo "
";
}
else
{
echo "Illegal 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 "Legal URL format";
echo "
";
echo "
";
}
else
{
echo "Illegal url format";
echo "
";
echo "
";
}
}