问题很简单我需要在${value}
中找到所有值,例如:
*test text $(1123) test texttest text${asd} test text test text test text ${123} test text[123132] test text [1231231]*
我应该
asd
123
我做过像THIS这样的事情,但你可以看到它不能正常工作。
答案 0 :(得分:2)
答案 1 :(得分:1)
您可以使用后视来获得所需的结果:
了解更多
正则表达式(?<=\$\{)[^}]+
解释:
(?<= look behind to see if there is:
\$ '$'
\{ '{'
) end of look-behind
[^}]+ any character except: '}' (1 or more times)
示例代码:
String str = "test text $(1123) test texttest text${asd} test text test text test text ${123} test text[123132] test text [1231231]";
Pattern pattern = Pattern.compile("(?<=\\$\\{)[^}]+");
Matcher matcher = pattern.matcher(str);
while(matcher.find()){
System.out.println(matcher.group());
}
输出:
asd
123