[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);

    }

}

 

posted @ 2016-08-05 10:09  Aviva_ye  阅读(1109)  评论(0编辑  收藏  举报