重温JavaScript中的正则表达式 js学习笔记(2)


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/

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wfydfw.html