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 }