正则表达式获取匹配字符串

String s = "姓名是${name},密码是${password}";
Pattern pat = Pattern.compile("\\$\\{[a-zA-Z0-9_-]*\\}");
Matcher mat = pat.matcher(s);
while(mat.find()){
String mm=mat.group(0);
String[] str=mm.split("\\{");
String[] str2=str[1].split("\\}");
System.out.println(str2[0]);

}

posted @ 2015-05-12 16:07  萧雪痕  阅读(545)  评论(0编辑  收藏  举报