title: Best method to replace a string with a string containing backslashes (\)
body: <p>I'm trying to update a stored NT account (Domain\user) with a new account. The new account comes as a String object.</p>
  
  <p>I call my replaceAccount method to perform this, by running this line:</p>
  
  <pre><code>tempAcct.setDefinition(ExtractNTAccount.matcher(tempAcct.getDefinition()).replaceFirst("nt=\""+newNTLogin+"\""));
  </code></pre>
  
  <p>If the NT Account is "HOME\jdoe", and I then output the definition field of tempAcct, I see the NT login as "HOMEjdoe" instead.</p>
  
  <p>By checking the replaceFirst method javadoc, the following can be read:</p>
  
  <blockquote>
    <p>"Note that backslashes () and dollar
    signs ($) in the replacement string
    may cause the results to be different
    than if it were being treated as a
    literal replacement string; see
    Matcher.replaceFirst(java.lang.String).
    Use
    Matcher.quoteReplacement(java.lang.String)
    to suppress the special meaning of
    these characters, if desired."</p>
  </blockquote>
  
  <p>So, I've found that if instead of passing the NT account as it is ("HOME\jdoe") I pass <strong>"HOME"+Matcher.quoteReplacement("\\")+"jdoe"</strong>, or <strong>"HOME\\\\jdoe"</strong>, I then get correct results after using the replaceFirst method.</p>
  
  <p>Is this the best method we can use or I'm totally misunderstanding how to use the Matcher.quoteReplacement() method?</p>