我从RegExp.test()和RegExp.match()得到不同的结果,这取决于我是用单引号还是双引号定义要测试的字符串。解释器认为字符串是相同的,但RegExp匹配用单引号定义的字符串而不是另一个。怎么可能呢?
var str1 = 'abc';
var str2 = "abc";
var re = /abc/g;
console.log('test of str1 === str2:');
console.log(str1 === str2); // Is true, as expected.
console.log('test single quotes defined string:');
console.log(re.test(str1)); // Is true, as expected.
console.log('test double quotes defined string: ');
console.log(re.test(str2)); // Is false! But str1 === str2!