联系邮箱:254200493@qq.com 登录 注册

常用的正则表达式

2019-12-21 15:30:26

常用的正则表达式:
邮箱:^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
域名:[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
中文:^[\u4e00-\u9fa5]{0,}$
日期格式:^\d{4}-\d{1,2}-\d{1,2}
IP地址:/((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/


如何提取html内容包含的图片地址,以下是PHP的写法:

preg_match_all ('/<img(?:.*?)src="(.*?)"(?:.*?)>/', $html, $matches);
$data = [];
if(count($matches)==2){
$data = $matches[1];
} return $data;




相关文章