How can I remove a complete line if it contains a specific string like the following?
#RemoveMe
How can I remove a complete line if it contains a specific string like the following?
#RemoveMe
If you have a multi-line string, you could use a RegExp with the m
flag:
var str = 'line1\n'+
'line2\n'+
'#RemoveMe line3\n'+
'line4';
str.replace(/^.*#RemoveMe.*$/mg, "");
The m
flag will treat the ^
and $
meta characters as the beginning and end of each line, not the beginning or end of the whole string.