被PHP的正则打败了。。。
我简单的匹配abba 这样的4个连续的数字,里面使用了子表达式和反向引用,结果没有捕获到,真不知道为什么,我哪里写错了?
<?php
header("Content-type:text/html;charset=utf-8");
$str="fdsafsdafsgfdag1223fa1551sdfassd3265";
$mypreg="/(\d)(\d)\2\1/";//匹配abba式的数字,即上面的1551
$mycon="这是数字";
$str=preg_replace($mypreg,$mycon,$str);
echo $str."<br/>";
$a = "/(\d)(\d)\2\1/";bool(false) string(12) "/(\d)(\d)/" string(14) "/(\d)(\d)\2\1/"
$b = '/(\d)(\d)\2\1/';
var_dump($a == $b);
var_dump($a, $b);
$a = "/(\d)(\d)\\2\\1/";bool(true) string(14) "/(\d)(\d)\2\1/" string(14) "/(\d)(\d)\2\1/"
$b = '/(\d)(\d)\2\1/';
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/>";