我们在开发一些模板文件的时候,经常需要查找赋值标签里的内容。
例如,模板如下。
1 |
大家好,我的名字叫${username},我的电话号码是${phoneNumber},我所在的公司是${company},谢谢。 |
代码
1 2 3 4 5 |
Pattern regex = compile("\\$\\{([^}]*)\\}"); Matcher matcher = regex.matcher(testStr); while(matcher.find()) { System.out.println(matcher.group(1)); } |
0