网上一段简单的preg_match替换 不明
<br />$string = "Is is the cost of of gasoline going up up"; <br /> $pattern = "/\b([a-z]+) \\1\b/i"; <br /> if(preg_match($pattern, $string,$arr)){<br /> print_r($arr);<br /> echo preg_replace($pattern, '$1', $string);<br /> }<br />
输出
<br />Array<br />(<br /> [0] => Is is<br /> [1] => Is<br />)<br />Is the cost of gasoline going up<br />
我理解的preg_match($pattern,$repalce,$subject)是用pattern从subject匹配到各个分组,然后用replace规定的显示方式,重新输出
$pattern = “/\b([a-z]+) \\1\b/i” 匹配到的只有Is is 和Is
重新输出怎么会输出一整句话 Is the cost of gasoline going up
还有什么时候用$1 什么时候用\\1 获取子模式匹配的内容 在双引号和单引号里又有什么要求?