title: Backreferences Syntax in Replacement Strings (Why Dollar Sign?)
body: <p>In Java, and it seems in a few other languages, backreferences in the pattern are preceded by a backslash (e.g. <code>\1</code>, <code>\2</code>, <code>\3</code>, etc), but in a replacement string they preceded by a dollar sign (e.g. <code>$1</code>, <code>$2</code>, <code>$3</code>, and also <code>$0</code>).</p>
  
  <p>Here's a snippet to illustrate:</p>
  
  <pre><code>System.out.println(
      "left-right".replaceAll("(.*)-(.*)", "\\2-\\1") // WRONG!!!
  ); // prints "2-1"
  
  System.out.println(
      "left-right".replaceAll("(.*)-(.*)", "$2-$1")   // CORRECT!
  ); // prints "right-left"
  
  System.out.println(
      "You want million dollar?!?".replaceAll("(\\w*) dollar", "US\\$ $1")
  ); // prints "You want US$ million?!?"
  
  System.out.println(
      "You want million dollar?!?".replaceAll("(\\w*) dollar", "US$ \\1")
  ); // throws IllegalArgumentException: Illegal group reference
  </code></pre>
  
  <p>Questions:</p>
  
  <ul>
  <li>Is the use of <code>$</code> for backreferences in replacement strings unique to Java? If not, what language started it? What flavors use it and what don't?</li>
  <li>Why is this a good idea? Why not stick to the same pattern syntax? Wouldn't that lead to a more cohesive and an easier to learn language?
  
  <ul>
  <li>Wouldn't the syntax be more streamlined if statements 1 and 4 in the above were the "correct" ones instead of 2 and 3? </li>
  </ul></li>
  </ul>