基础
http://deerchao.net/tutorials/regex/regex.htm#metacode
完善匹配中文的Php正则表达式
http://www.php100.com/html/webkaifa/zhengzebiaodashi/2011/0213/7513.html
php提供的原生处理编码的正则
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php $string=" (包含首月600分钟区内语音、300M流量、100条短信、免6元手机邮箱)"; mb_regex_encoding("UTF-8"); mb_ereg_search_init($string); //mb_ereg_search("(d+)(分钟|M|条|元)"); echo "<pre>"; while($match = mb_ereg_search_regs ("(d+)(分钟|M|条|元)([^、)]+)")){ var_export($match); }; exit;
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><pre><?php // 零宽断言,需要理解的是间隙 //特别注意零,这种是间隙,表示匹配但不包括 preg_match_all("/ab(?=c)/", "abc abd",$data); print_r($data); /** * Array ( [0] => Array ( [0] => ab ) ) */ //间隙后不是什么 preg_match_all("/ab(?!c)/", "abc abd",$data); print_r($data); /** * Array ( [0] => Array ( [0] => ab ) ) */ //括号不包括 preg_match_all("/ab(?:c)/", "abc abd",$data); print_r($data); /** * //这个和上面是没有关系的,只是顺便做补充 Array ( [0] => Array ( [0] => abc ) ) */ //包括间隙 preg_match_all("/ab(?>c)/", "abc abd",$data); print_r($data); echo "负向0宽断言<BR>"; preg_match_all("/(?<=c)ab/", "cab dab",$data); print_r($data); /** * Array ( [0] => Array ( [0] => ab ) ) */ preg_match_all("/(?<=c)ab/", "<=cab dab",$data); print_r($data); /** * Array ( [0] => Array ( [0] => <=cab ) ) */ preg_match_all("/(?<!c)ab/", "<=cab dab",$data); print_r($data); /** * Array ( [0] => Array ( [0] => <=dab ) ) */ preg_match_all("/(?:<=c)ab/", "<=cab dab",$data); print_r($data); /** * Array ( [0] => Array ( [0] => <=cab ) ) */ exit;
匹配多个不相同字正则 ,有人说无解呀~
$s = "abcd1231daaa23abcxde23abcdeef3abcdefg3abcdefgh3abcdefghi3abccdefghij"; $flag = preg_match_all ( '/([a-z])(?!1)([a-z])(?!1|2)([a-z])(?!1|2|3)([a-z])(?!1|2|3|4)([a-z])(?!1|2|3|4|5)([a-z])/', $s, $result ); var_export ( $flag ); var_export ( $result ); /** * array ( * 0 => 'abcdef', * 1 => 'abcdef', * 2 => 'abcdef', * 3 => 'abcdef', * 4 =>'cdefgh', ) */
补充替换反斜杠 =>
$value=preg_replace("/\\/", "", $value);
Its Pleasure to realize your blog.The over content is relatively extraordinary, and I really enjoyed reading your blog and points that you just expressed. I incredibly like to glimpse back over a regular basis,post additional from the topic.Thanks for sharing…keep writing!