0

I get different results from RegExp.test() and RegExp.match() depending on whether I defined the strings to test with single quotes or double quotes. The interpreter thinks the strings are identical, but the RegExp matches the one defined with single quotes and not the other. How can this be possible?

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!
hellmelt
  • 219
  • 3
  • 6

0 Answers0