title: Javascript - Remove '\n' from string
body: <pre><code>var strObj = '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n{"text": true, ["text", "text", "text", "text"], [{ "text", "text" }]}\n\n\n'
  </code></pre>
  
  <p>I am trying to sanitize a string by stripping out the <code>\n</code> but when I do <code>.replace(/\\\n/g, '')</code> it doesn't seem to catch it. I also Google searched and found:</p>
  
  <blockquote>
    <p>..in accordance with JavaScript regular expression syntax you need two backslash characters in your regular expression literals such as <code>/\\/</code> or <code>/\\/g</code>.</p>
  </blockquote>
  
  <p>But even when I test the expression just to catch backslash, it returns false:
  <code>(/\\\/g).test(strObj)</code></p>
  
  <p>RegEx tester captures <code>\n</code> correctly: <a href="http://regexr.com/3d3pe" rel="noreferrer">http://regexr.com/3d3pe</a></p>