E-mail regular expression and URL regular expression _ PHP Tutorial

Source: Internet
Author: User
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"
";
}
}

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.