java正则表达式处理花括号内容替换赋值
@Test
public  void replaceStr() {
System.out.println("将{gid}替换为某值");
String name1 = "name";
String cql = "MATCH p=({gid: {gid}})-[r:paper_yantian1586528279416]->() RETURN p LIMIT 25 ";
System.out.placeAll("\\{[gid^}]*\\}", "\""+name1+"\"}"));
System.out.println("将{name}替换为某值,{name}中的name可动态传值被替换");
String sql = "select name from person where name = {name} and sex = %s";
String name = "name";
int val = 123;
System.out.placeAll("\\{["+name+"^}]*\\}", val+""));
System.out.println("暴⼒替换");
System.out.place("{name}", "123"));
java replace方法System.out.println("去除花括号并赋值");
String str = "{f.name} and {f.age}";
String pattern = "\\{[^}]*\\}";
Pattern p = Patternpile(pattern);
Matcher m = p.matcher(str);
while (m.find()) {
String g = m.group();
String target = g.substring(1, g.length() - 1);//去掉花括号
str = place(g,target + " <= '2019-09-09'");
}
System.out.println("str:" + str);
}
执⾏结果

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。