正则匹配为0的数据(0.00)

发布时间 2023-05-31 13:49:28作者: 睡个好觉"
mongo的查询某字段不为0
// 查询差异不为0的数据
Pattern compile = Pattern.compile("^[0.]*$");
// mongo的查询
Criteria criteria = new Criteria();
criteria.and("qtyStuDiff").not().regex(compile);
正则表达式匹配为0
public static void main(String[] args) {

        String str = "0.000";
        String pattern = "^[0.]*$";

        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
        System.out.println(m.matches()); // true
}