我不确定这里的区别是什么,也不知道为什么一个有效而另一个无效。有人可以解释一下吗?
//The string to search through
var str = "This is a string /* with some //stuff in here";
//This one will NOT work, it alerts an empty "match"
var regEx = new RegExp( "(\/\*)", "g" );
//This one also will NOT work (tried just in case escaping was the issue)
var regEx2 = new RegExp( "(/*)", "g" );
//This one DOES work
var regEx3 = /(\/\*)/g;
var match = null;
//Trying the first one, it alerts ","
if ( match = regEx.exec( str ) ) alert( match );
//Trying the second one, it alerts ","
if ( match = regEx2.exec( str ) ) alert( match );
//Trying the third one, it alerts "/*,/*" - it works!
if ( match = regEx3.exec( str ) ) alert( match );
我做错了什么?