PHP正则表达式
<?php error_reporting(E_ALL); //报告所有错误,error_reporting(0)设置会忽略错误 //与perl里面的正则类似,/****/i,//为正则表达式界定符,js也可这样表示 $regex = '/^http:\/\/([\w.]+)\/([\w]+)\/([\w]+)\.html$/i'; $str = 'http://www.youku.com/show_page/id_ABCDEFG.html'; $matches = array(); if(preg_match($regex, $str, $matches)){ var_dump($matches); } echo "<br/>"; $reg = '/(?<num>\d+)/i'; $k = "asd33sdfds4434dsdfd2222"; $m_array = array(); //匹配所有的 if(preg_match_all($reg, $k, $m_array)) { var_dump($m_array); } //将连续的数字替换为一个* $a = preg_replace('/(\d+)/i', '*', 'asd3343ddsf999dfdf000fff'); echo "<br/>".$a; //用,.;符号分割字符 $sv = preg_split('/[,\.;]/i', "aa,dd;xxx.sdsd"); var_dump($sv); ?>