replece 使用函数作为第二参数
作者:互联网
var a = "The boy is gay.";
var b = /boy/;
console.log(b) —— /boy/ x相当于给他加一个 "" 转义
var c = a.replace(b, function (s) { s是a中匹配到的元素即在a中找到b
return "girl";
});
console.log(c) —— 输出 The girl is gay.
标签:boy,console,函数,gay,replece,参数,var,girl,log 来源: https://blog.csdn.net/weixin_47450691/article/details/119062700