正则替换

1

String urlTemplate="com/{a}/{b}/{c}/home.js";
        Pattern pattern = Pattern.compile("\\{\\w+\\}");
        Matcher m = pattern.matcher(urlTemplate);
        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            // 将匹配之前的字符串复制到sb,再将匹配结果替换为:"0",并追加到sb
            m.appendReplacement(sb, "0");
        }
        m.appendTail(sb);

        String url=sb.toString();
        System.out.println(url);

 

posted @ 2017-12-04 14:55  zslm___  阅读(182)  评论(0编辑  收藏  举报