我有这个JS代码:
var str = "foo bar";
var res1 = str.replace(new RegExp('foo\\b', 'g'), "BAZ");
var res2 = str.replace(new RegExp('foo', 'g'), "BAZ");
console.log("Result1: " + res1 + " Result2: " + res2);
控制台上的结果Chrome Version 69.0.3497.81 (Official Build) (64-bit)
是:
Result1: BAZ bar Result2: BAZ bar
现在我测试相同的PHP
代码V8Js
扩展测试相同的代码:
PHP代码:
<?php
$v8 = new V8Js();
$JS = <<<EOT
var str = "foo bar";
var res1 = str.replace(new RegExp('foo\\b', 'g'), "BAZ");
var res2 = str.replace(new RegExp('foo', 'g'), "BAZ");
print("Result1: " + res1 + " Result2: " + res2);
EOT;
echo $v8->executeString($JS);
PHP 7.2.9 (cli) (built: Aug 15 2018 05:57:41) ( NTS MSVC15 (Visual C++ 2017) x64 )
WithV8Js Version 2.1.0
扩展的结果:
Result1: foo bar Result2: BAZ bar
为什么结果不同result1
?!!!