title: Java String ReplaceAll and ReplaceFirst Fails at $ Symbol at Replacement Text
body: <p>I wrote this code:</p>
  
  <pre><code>public static void main(String args[]) throws Exception {
      String template = "The user has spent amount in a day";
      String pattern = "amount";
      String output = template.replaceAll(pattern, "$ 100");
      System.out.println(output);
  }
  </code></pre>
  
  <p>This is what happens when I run it:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference
          at java.util.regex.Matcher.appendReplacement(Matcher.java:713)
          at java.util.regex.Matcher.replaceAll(Matcher.java:813)
          at java.lang.String.replaceAll(String.java:2190)
          at demo.BugDemo.main(BugDemo.java:16)
  Java Result: 1
  </code></pre>
  
  <p>I'm reading data from a file. Should I escape all <code>$</code> symbols in the file data, or is this an unnecessary process? Is there any other class or library to handle this situation?</p>
  
  <p>What is the problem with having a special symbol in the replacement text (not in the regex)?</p>
  
  <p>Notes:</p>
  
  <ul>
  <li><p>I don't want to check every character to escape. That's why I am asking this question.</p></li>
  <li><p>I'm using Java 6.</p></li>
  </ul>