Email and URL Regular Expressions

Source: Internet
Author: User

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> ";
}
}

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.