2011/12/14

java replaceAll with $

as $ is one of the symbol used in regular expression
it will fail at replpace all


solution

replace all $ to \\$
String a = "$38 Apple";
a = a.replaceAll("\\$", "\\\\\\$");

replace
String b = "testing testing REPLACE_ME testing testing";
String finalStr= start.replaceAll("REPLACE_ME", a);

沒有留言:

發佈留言