逃避号码会发生什么?

时间:2016-10-26 11:48:17

标签: javascript php html string numbers

我有这个代码替换了REGEX捕获组与back-reference的匹配,但匹配的文本总是被替换为什么,即切割。

代码:

$str = 'string is string';
$replacement_result = preg_replace("/(\w+) is (\w+)/","\1 this \3", $str);

echo $replacement_result;
// results was 'is'

然后我注意到替换参数字符串是双引号并且是在逃避数字(我认为它可以正常工作),所以我将双引号更改为单引号

$str = 'string is string';
                                                     // changes here
$replacement_result = preg_replace("/(\w+) is (\w+)/",'\1 this \3', $str);

echo $replacement_result;
// results was 'string this string'

我甚至在document.write()中尝试Javascript和转义了数字,并且'相同的结果(没有)。

所以很明显这是我第一次遇到这个,并且有一个非常简单的1 - 2行答案。 转义号码后会发生什么?

1 个答案:

答案 0 :(得分:0)

根据official documentation,在双引号字符串中,范围update emp set . . . where comm = (select max(e2.comm) from emp e2); 中后跟1..3个数字的反斜杠序列被解释为八进制表示法中的字符:

  

0..7与常规字符匹配的字符序列   expression是八进制表示法中的一个字符,它以静默方式溢出   适合一个字节(例如\[0-7]{1,3}