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