如果我只关心是否至少有一个匹配项,是否有任何理由检查返回数组的长度,或者只是检查返回值是否不够 null?
javascript正则表达式匹配
var str = "The rain in SPAIN stays mainly in the plain";
var n = str.match(/ain/g);
if(n && n.length > 0) {alert('at least one match');
// Or
if(n) {alert('at least one match');