Home >Backend Development >PHP Tutorial > php正则表达式跟js正则表达式居然不一样

php正则表达式跟js正则表达式居然不一样

WBOY
WBOYOriginal
2016-06-13 12:42:39920browse

php正则表达式和js正则表达式居然不一样?
我使用js的正则没有问题,然后同样的写成php正则,居然匹配不到,两者的正则不一样?


如,我匹配4个连续且全部相同的数字,同样的串,同样的规则,js可以匹配成功,php匹配不到,

js:

var str="fasdgasgdfgfduuuuuu1221uuuuufasdfsdfsdaf4444";<br />
var myreg=/(\d)\1{3}/gi;<br />
var mycon="数字";<br />
var str=str.replace(myreg,mycon);<br />
document.write(str);<br />


php:
<?php<br />
header("Content-type:text/html;charset=utf-8");<br />
$str="fasdgasgdfgfduuuuuu1221uuuuufasdfsdfsdaf4444";<br />
$mypreg="/(\d)\1{3}/i";<br />
$mycon="这是数字";<br />
echo $str."<br/>";		<br />
$str=preg_replace($mypreg,$mycon,$str);<br />
echo $str."<br/>";


js成功将4444匹配,php没有获取到。惊!!!!!!!!!!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn