I am attempting to replace parts of a string that don\'t match a regular expression pattern using JavaScript. This is functionally equivalent to using the <
If I understand you correctly, this should be one possible solution:
'aforementioned'.replace(new RegExp(pattern + '|.', 'gi'), function(c) { return c === pattern ? c : '*'; }); >> "*fore*********"