Is the use of $ for backreferences in replacement strings unique to Java?
No. Perl uses it, and Perl certainly predates Java’s Pattern
class. Java’s regex support is explicitly described in terms of Perl regexes.
For example: http://perldoc.perl.org/perlrequick.html#Search-and-replace
Why is this a good idea?
Well obviously you don’t think it is a good idea! But one reason that it is a good idea is to make Java search/replace support (more) compatible with Perl’s.
There is another possible reason why $
might have been viewed as a better choice than \
. That is that \
has to be written as \\
in a Java String literal.
But all of this is pure speculation. None of us were in the room when the design decisions were made. And ultimately it doesn’t really matter why they designed the replacement String syntax that way. The decisions have been made and set in concrete, and any further discussion is purely academic … unless you just happen to be designing a new language or a new regex library for Java.