If you have a multi-line string, you can use RegExp with the flag m:
var str = 'line1\n'+
'line2\n'+
'#RemoveMe line3\n'+
'line4';
str.replace(/^.*#RemoveMe.*$/mg, "");
Flag mhandles wildcard characters ^and $both the beginning and end of each line, rather than the beginning or end of the whole line.
source
share