var a = "The boy is gay.";
var b = /boy/;
console.log(b) //输出/boy/,b相当于给他加一个 "" 转义
var c = a.replace(b, function (s) { //s是a中匹配到的元素即在a中找到b
return "girl";
});
console.log(c) //输出 The girl is gay.
replece 使用函数作为第二参数
于 2021-07-24 19:24:56 首次发布