php正则表达式和js正则表达式居然不一样?
我使用js的正则没有问题,然后同样的写成php正则,居然匹配不到,两者的正则不一样?
如,我匹配4个连续且全部相同的数字,同样的串,同样的规则,js可以匹配成功,php匹配不到,
js:
var str="fasdgasgdfgfduuuuuu1221uuuuufasdfsdfsdaf4444";
var myreg=/(\d)\1{3}/gi;
var mycon="数字";
var str=str.replace(myreg,mycon);
document.write(str);
<?php
header("Content-type:text/html;charset=utf-8");
$str="fasdgasgdfgfduuuuuu1221uuuuufasdfsdfsdaf4444";
$mypreg="/(\d)\1{3}/i";
$mycon="这是数字";
echo $str."<br/>";
$str=preg_replace($mypreg,$mycon,$str);
echo $str."<br/>";
$a = "/(\d)\1{3}/i";bool(false) string(11) "/(\d){3}/i" string(12) "/(\d)\1{3}/i"
$b = '/(\d)\1{3}/i';
var_dump($a == $b);
var_dump($a, $b);
$str="fasdgasgdfgfduuuuuu1221uuuuufasdfsdfsdaf4444";
$mypreg='/(\d)\1{3}/i';
$mycon="这是数字";
echo $str."<br/>";
$str=preg_replace($mypreg,$mycon,$str);
echo $str."<br/>";
\字符,最好都是用\\来表示,这样是不会出现歧义的,尽管单引号仅检测\'转义