处理办法
用JDK提供的方法,对特殊字符进行处理
replacement = java.util.regex.Matcher.quoteReplacement(replacement);
public static void main(String[] args) { String regex = "str"; String replacement = "a$bc$d"; replacement = java.util.regex.Matcher.quoteReplacement(replacement); String str = "test str replace."; String str1 = str.replaceAll(regex, replacement); System.out.println(str1); }