replace方法

var str = 'hello abc abc';
// abc替换成bbb
let result = str.replace('abc', 'bbb')
// let result = str.replace(/abc/g, 'bbb')
console.log(result);

// abc,保留b,b大写
let result2 = str.replace(/a(b)(c)/g, '$1');
console.log(result2)
let result1 = str.replace(/a(b)c/g, function(match, $1) {
    // console.log(args);
    console.log(match, $1)
    return $1.toUpperCase();
})

console.log(result1);
原文地址:https://www.cnblogs.com/yess/p/13991423.html