Backreferences Syntax in Replacement Strings (Why Dollar Sign?)
问题 In Java, and it seems in a few other languages, backreferences in the pattern are preceded by a backslash (e.g. \1 , \2 , \3 , etc), but in a replacement string they preceded by a dollar sign (e.g. $1 , $2 , $3 , and also $0 ). Here's a snippet to illustrate: 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