1.正則表達(dá)式的作用:分割,查找,匹配,替換 字符串
2.分隔符:正斜線(/),hash符(#)以及取反符號(hào)(~)。
3.通用原子:d D s S w W
4.原子符
5. 模式修正符
6.后向引用
7.貪婪模式
8.正則表達(dá)式PCRE函數(shù) prge_match()
, preg_match_all()
, preg_replace()
, preg()_split()
.
解題方法方法
寫出一個(gè)要匹配的字符串
自左向右的順序使用正則表達(dá)式的原子和元字符進(jìn)行拼接
最終加入修正模式
練習(xí)常見的正則表達(dá)式(手機(jī)號(hào)碼,身份證,email,url等等)
139開頭的手機(jī)號(hào)碼
$str = '13988888888'; $partten = '/^139/d{8}$/'; preg_match($partten, str, $match); var_dump($match);
取出 html頁面中所有img標(biāo)簽的sr 的值
$str = '<img id=content"" src="高清無碼.jpg" alt="高清無碼">'; $partten = '/<img.*?src="(.*?)".*?/?>/i'; preg_match($partten, $str, $match); var_dump($march);