java正则解析${}
程序员文章站
2022-07-13 11:57:27
...
java正则解析${}
String property = "带有${}需要匹配的字符串";
//懒匹配${}
String regex = "\\$\\{(.*?)}";
Pattern pattern = Pattern.compile(regex);
Matcher matcher;
//自旋进行最小匹配,直到无法匹配
while((matcher = pattern.matcher(property)).find()) {
//替换匹配内容
property = property.replace(matcher.group(), System.getenv(matcher.group(1)));
}
Pattern PATTERN = Pattern.compile("\\$\\{\\s*(\\w+)\\s*(([\\+\\-])\\s*(\\d+)\\s*)?\\}");
上一篇: 卷帘