且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换与正则表达式不匹配的字符串部分

更新时间:2023-02-26 11:25:24

如果我理解正确,这应该是一种可能的解决方案:

If I understand you correctly, this should be one possible solution:

'aforementioned'.replace(new RegExp(pattern + '|.', 'gi'), function(c) {
    return c === pattern ? c : '*';
});

>> "*fore*********"