var str = "dogdogdog"; var str2 = str.replace(/dog/g,"cat"); console.log(str2);
参考:https://www.jb51.net/article/23762.htm?tdsourcetag=s_pcqq_aiomsg
str = "dog dog dog12"; str = str.replace(new RegExp("[d]","gm"),"_"); console.log(str);
输出:_og _og _og12
参考:https://www.runoob.com/jsref/jsref-obj-regexp.html
标签:www,console,log,正则表达式,javascript,dog,replace,replaceall,str From: https://www.cnblogs.com/2008nmj/p/17989021