标签:and find java select string pattern system bool compile
查找是否包含字串 查询是否包含 #{name} 片段 这里有包含所以返回true
String context = "select * from t_user where (name = #{name} or username = #{name}) and age > #{age}"; String regex = ".*\\#\\{name\\}.*"; boolean is = Pattern.matches(regex,context);
匹配所有 #{任何内容}
String context = "select * from t_user where (name = #{name} or username = #{name}) and age > #{age}"; //String regex = "\\{([^}]*)\\}"; String regex = "\\#\\{(.*?)\\}"; //创建 Pattern 对象 Pattern r = Pattern.compile(regex); //创建 Matcher 对象 Matcher m = r.matcher(context); while (m.find()){ System.out.println(m.group() + "=" + m.group(1)); }
输出内容为
#{name}=name #{name}=name #{age}=age
标签:and find java select string pattern system bool compile
原文地址:https://www.cnblogs.com/rchao/p/11011528.html