java.lang.IllegalArgumentException: Illegal group

String s = "  $$";
s = s.replaceAll("\\s+\\$\\$","$$");

throw exception 

java.lang.IllegalArgumentException: Illegal group 


Use "\\$\\$" in the second parameter:

String s="  $$";
s=s.replaceAll("\\s+\\$\\$","\\$\\$");

The $ is group symbol in regex's replacement parameter

So you need to escape it


the second parameter also need to escape!


你可能感兴趣的:(java)