[Java] 特殊正则-替换字符串
public class Test { public static void main(String[] args) { String str = "2412rhttp://192.168.6.200:8080/file/123.jpgdsfwr23423423http://192.168.6.200:8080/file/123.jpgrtthweehrrh"; String reg = "\\$\\{ctx_file\\}"; String filePath = "http://192.168.6.200:8080"; String strRep = str.replaceAll(filePath, reg); System.out.println(strRep); String strRep2 = str.replaceAll(reg, filePath); System.out.println(strRep2); } }