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

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

WBOY
Release: 2016-06-13 12:42:39
Original
930 people have browsed it

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 />
Copy after login
Copy after login


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/>";
Copy after login
Copy after login


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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template