java正则解析${}
java正则解析${}
1 String property = "带有${}需要匹配的字符串";
2 //懒匹配${}
3 String regex = "\\$\\{(.*?)}";
4 Pattern pattern = Pattern.compile(regex);
5 Matcher matcher;
6 //自旋进行最小匹配,直到无法匹配
7 while((matcher = pattern.matcher(property)).find()) {
8 //替换匹配内容
9 property = property.replace(matcher.group(), System.getenv(matcher.group(1)));
10 }