title: Regex to match all backslash characters, except new line, carriage return, etc
body: <p>I'm looking for a regex to escape all backslash characters into double blackshash characters, except for newlines, carriage returns, etc..</p>
  
  <p>This function:</p>
  
  <pre><code>Public Function EscapeInvalidCharacters(ByVal str As String) As String
      str = str.Replace("\", "\\")            ' Backslash
  
      str = str.Replace("'", "\'")            ' Single quote
      str = str.Replace("""", "\""")          ' Double quote
      str = str.Replace(vbNewLine, "\n")      ' New line
      str = str.Replace(vbCr, "\r")           ' Carriage return
      str = str.Replace(vbTab, "\t")          ' Horizontal tab
      str = str.Replace(vbBack, "\b")         ' Backspace
      str = str.Replace(vbFormFeed, "\f")     ' Form feed
  
      Return str
  End Function
  </code></pre>
  
  <p>with this input:</p>
  
  <pre><code>"This is a test.\nThis is another test.\n"
  </code></pre>
  
  <p>Wrongly, generates the following output:</p>
  
  <pre><code>"This is a test.\\nThis is another test.\\n"
  </code></pre>
  
  <p>Is it possible to alter the line <code>str = str.Replace("\", "\\")</code> so that it doesn't alter the newlines?</p>