Line breaks are casuing it to break and I can't get the m modifier to work so we can add an extra replace.
js code:
html = html.replace(/\n/gi, "").replace(/\<table.+?table\>/gi, "");
If you wanted to, you could replace the \n with a unique string so it can be put back together again...
js code:
html = html.replace(/\n/gi, "this-used-to-be-a-line-break").replace(/\<table.+?table\>/gi, "");
html = html.replace(/this-used-to-be-a-line-break/gi, "\n");
// This is just so the source formatting looks good when viewed,
// rather than all being on one line