求大神帮忙写个java匹配#{}的正则表达式,不包含#{},取#{}中的值。
public static void main(String[] args) {
String regex = "\\#\\{([^}]*)\\}";//匹配大括号
// private static String regexx = "\\(([^}]*)\\)";//匹配小括号
String dakuohao = "{a+b}=#{c+d}>#{d}";
Pattern compile = Pattern.compile(regex);
Matcher matcher = compile.matcher(dakuohao);
while(matcher.find()){
String group = matcher.group();
System.out.print(group+";");
}
}
这个是可以匹配并取到值的,但值中有#{},我想只取内容不带#{}。求大神指点
结果截取:group.substring(1, group.length() - 2)
多谢老哥的匹配#{}的正则
匹配#{}里面的正则相信你现在也已经不需要了,留给后来人使用
(?<=\#\{)([^}]*)(?=\})