<?php
header("Content-Type: text/html;charset=utf-8");
//*普通字符
$pattem = '/[0-9]/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f 231 fasdf1sd32f1315642315131351321534132 fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*非打印字符
$pattem = '/\n/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*自定义字符
$pattem = '/[a-z]/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*二、元字符 .代表换行符之外的全部字符
$pattem = '/32./';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*二、元字符 匹配两个或多个内容
$pattem = '/32|41/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*二、元字符 取反 取括号内之外的书,排除括号里面的
$pattem = '/[^1234]/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*二、元字符 从第一个字符开始匹配,必须是^符号后面一模一样的内容
$pattem = '/^[a-z]/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*二、元字符 从最后一个字符开始匹配
$pattem = '/[0-9a-zA-Z]$/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*三、量词(限定符)n词 等于3次
$pattem = '/[0-9]{3}/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*三、量词(限定符) 不少于1次
$pattem = '/[0-9]{1,}/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*三、量词(限定符)大于1个 小于3个
$pattem = '/[0-9]{1,3}/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*三、量词(限定符匹配1次或多次
$pattem = '/[0-9]+/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*三、量词(限定符) 匹配连续的0次或1次
$pattem = '/[0-9]?/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 匹配任意一个十进制数
$pattem = '/\d/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 匹配出十进制以外的数
$pattem = '/\D/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 匹配任意一个字母、数字、下划线
$pattem = '/\w/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 匹配除任字母、数字、下划线之外的
$pattem = '/\W/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 空白字符
$pattem = '/\s/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 除空白字符以外的
$pattem = '/\S/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 边界 就是中间有没有空格 分开的数
$pattem = '/\b/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*四、预定义字符 除边界以外的
$pattem = '/\B/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w23544253442132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*五、预定义字符 匹配连续的0次或1次
$pattem = '/\?/';
$str = 'd1f3w35fw4fw4efw4ef5w4efw4efwefwfwemhgekrthege3gergregdasfdqef2w235442534+ ? * + ?$42132f
231 fasdf1sd32f1315642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*六、分组符
$pattem = '/(对对对|阿萨德)|([0-9])/';
$str = 'd1f3w35fw4fsad阿萨德w4efw4ef5对对对w4efw4efwefwfwemhgekrthe对对对ge3gergregdasfdqef2w235442534+ ? * + ?$42132f
231 fasdf1sd32f1315对对对642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*叮叮咚咚fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*七、修正符 加U取消贪婪模式 默认是贪婪模式 正则表达式有贪婪模式和懒惰模式
$pattem = '/ge.*/U';
$str = 'd1f3w35fw4fsad阿萨德w4efw4ef5对对对w4efw4efwefwfwemhgekrthe对对对ge3gergregdasfdqef2w235442534+ ? * + ?$42132f
231 fasdf1sd32f1315对对对642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*叮叮咚咚fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*七、修正符 i忽略大小写
$pattem = '/ge*/i';
$str = 'd1f3w35fw4fsad阿萨德w4efw4ef5对对对w4efw4efwefwfwemhgekrthe对对对ge3gergregdasfdqef2w235442534+ ? * + ?$42132f
231 fasdf1sd32f1315对对对642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*叮叮咚咚fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*七、修正符 s忽略换行符
$pattem = '/fe*/s';
$str = 'd1f3w35fw4fsad阿萨德w4efw4ef5对对对w4efw4efwefwfwemhgekrthe对对对ge3gergregdasfdqef2w235442534+ ? * + ?$42132f
231 fasdf1sd32f1315对对对642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*叮叮咚咚fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
//*七、修正符 x 忽略空白
$pattem = '/ 5
1
3/x';
$str = 'd1f3w35fw4fsad阿萨德w4efw4ef5对对对w4efw4efwefwfwemhgekrthe对对对ge3gergregdasfdqef2w235442534+ ? * + ?$42132f
231 fasdf1sd32f1315对对对642315131351321534132
fwqe3frw1fw1fw2f1wfdfwfwf*叮叮咚咚fe1g23e1g3eg1ergwefwefw';
$a = preg_match_all($pattem,$str,$res);
echo print_r($a,true);
echo '<hr>';
echo print_r($res,true) ;
echo '<hr>';
?>