var myPattern = /[a-z]+/;var theStr = "this is a dog,that is a cat!"console.log(theStr.replace(myPattern, "a")); //a is a dog,that is a cat! 贪婪的,把this都匹配了!
var myPattern = /[a-z]+?/;var theStr = "this is a dog,that is a cat!"console.log(theStr.replace(myPattern, "a")); //ahis is a dog,that is a cat! 非贪婪的,只把this中的t匹配了!
最后,RegExp实例继承的toLocaleString()和toString()方法都会返回正则表达式的字面量,即/abc/
您可能感兴趣的文章: