[英]regular expression - parse classpath location
$JAR_REPO/nlb/grbox/smnt.jar
I want to get the string between $ and first / and this will be replaced with some other string. 我想获取$和first /之间的字符串,并将其替换为其他字符串。
Please help. 请帮忙。
Thanks. 谢谢。 Wells 韦尔斯
\$([^/]+)/.*
or, as a Java String: 或者,作为Java字符串:
"\\$([^/]+)/.*"
The JAR_REPO String will be the group(1)
: JAR_REPO字符串将为group(1)
:
Pattern pattern = Pattern.compile("\\$([^/]+)/.*");
Matcher matcher = pattern.matcher(yourstring);
if (matcher.find()) {
String jarRepo = matcher.group(1);
}
这种类型的递归解析方法可以与解析方法一起使用解释器模式逻辑来解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.