A useful regular matching phone number of the phone number of the mailbox address method _ Regular expression

Source: Internet
Author: User
Tags regular expression
Find a handy matching phone and phone number method, thanks, share here, hope to help more people

Match all URL addresses and linked content
Copy Code code as follows:

$str = "<a href= ' http://www.baidu.com ' target= ' _blank ' > Baidu </a>http://www<a href= ' http://www.sina.com ' target= ' _blank ' > Sina </a>kod ';

Preg_match_all ("/<a href=" ([\ "\"]) (http:\/\/([\w\d\.]) +) [^>]*> (. *?) <\/a>/i ", $str, $matches);

echo "<pre>";
Var_dump ($matches [2]);
echo "<br/>";
Var_dump ($matches [4]);

Matching mailboxes
Copy Code code as follows:

$emails = "wangzhanu@126.comha12wangzhanu@163.com";

Preg_match_all ("/([a-z0-9_\-\.] +) @ ([a-z0-9]+[_\-]?) \.) +[a-z]{2,3}/i ", $emails, $matches);

Var_dump ($matches [0]);

Match phone and phone number
Copy Code code as follows:

$tel = "13911112222sf010-44444442dfg18811112222";

Preg_match_all ("/1[3,5,8]{1}[0-9]{1}[0-9]{8}|0[0-9]{2,3}-[0-9]{7,8}" (-[0-9]{1,4})?/", $tel, $matches);

Var_dump ($matches);

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.