问题很简单,我需要找到的所有值${value}
例如,对于这样的文字:
*test text $(1123) test texttest text${asd} test text test text test text ${123} test text[123132] test text [1231231]*
我应该得到
asd
123
我已经做了类似THIS,但你可以看到它不工作的好。
问题很简单,我需要找到的所有值${value}
例如,对于这样的文字:
*test text $(1123) test texttest text${asd} test text test text test text ${123} test text[123132] test text [1231231]*
我应该得到
asd
123
我已经做了类似THIS,但你可以看到它不工作的好。
您可以使用向后看,以获得期望的结果:
探索更多
正则表达式(?<=\$\{)[^}]+
解释:
(?<= 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
我以为你死了=) – hwnd
感谢那就是我一直在寻找的 – user3353393