Q:

Remove lines that contain specific string

I have the following text and I want to remove line that only contains "&nbsp;" (i.e. remove first and last line but keep the third line) using JavaScript? 
Original:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br>     
&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDEF
&amp;nbsp;&amp;nbsp;&amp;nbsp;

Desired result:
&lt;br>      
&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDEF

A:

Give it a shot:
var output = str.replace(/(?:^|\r?\n)(?:&amp;nbsp;)*?(?=$|\r?\n)/g, '');

Fiddle
Also, in case you want to keep lines without any text replace * by +.  That is, considering this input text:
foo
&amp;nbsp;

baz

The first regex would remove the empty line:
foo
baz

While /(?:^|\r?\n)(?:&amp;nbsp;)+?(?=$|\r?\n)/g keeps it:
foo

baz

