title: regex to convert find instances a single \
body: <p>I am looking to replace <code>\n</code> with <code>\\n</code> but so far my regex attempts are not working (Really it is any \ by itself, \n just happens to be the use case I have in the data).</p>
  
  <p>What I need is something along the lines of:</p>
  
  <pre><code>any-non-\ followed by \ followed by any-non-\
  </code></pre>
  
  <p>Ultimately I'll be passing the regex to java.lang.String.replaceAll so a regex formatted for that would be great, but I can probably translate another style regex into what I need.</p>
  
  <p>For example I after this program to print out "true"...</p>
  
  <pre><code>public class Main
  {
      public static void main(String[] args)
      {
          final String original;
          final String altered;
          final String expected;
  
          original = "hello\nworld";
          expected = "hello\\nworld";
          altered  = original.replaceAll("([^\\\\])\\\\([^\\\\])", "$1\\\\$2");
          System.out.println(altered.equals(expected));
     }
  }
  </code></pre>
  
  <p>using this does work:</p>
  
  <pre><code>    altered  = original.replaceAll("\\n", "\\\\n");
  </code></pre>