正则表达式编写与收集
1. 匹配url地址
$reg = "/^(https?:\/\/)?(\w+\.)?(\w+\.)(\w+)(:\d+)?(\/\w+)*\/?(\?\w+=[^\s=&]+(&\w+=[^\s=&]+)*)?(#\w)?$/i"; $str = 'https://asdfewiiw.dsfsd.com:12323/user/index/?name="李四"&age=20&next=21#name'; // $str = 'https://dsfsd.com:12323/user/index/?name="李四"&age=20&next=21#name'; // $str = 'dsfsd.com:12323/user/index?name="李四"&age=20&next=21#name'; // $str = 'dsfsd.com/user/index?name="李四"&age=20&next=21#name'; // $str = 'dsfsd.com?name="李四"&age=20&next=21#name'; // $str = 'dsfsd.com?name="李四'; // $str = 'dsfsd.com'; $p = preg_match($reg, $str, $match); var_dump($match);
2. 匹配手机号
$reg = "/^1[3-9]\\d{9}$/"; $str = '13923222322'; $p = preg_match($reg, $str, $match); var_dump($match);
3. 匹配邮箱
1 $reg = "/^\w+@\w+\.\w{1,3}$/"; 2 $str = 'jiarenmen@okle.com'; 3 $p = preg_match($reg, $str, $match); 4 var_dump($match);