MongoDb Select查询Issue Whit正则表达式(以whit结尾,以Whits结尾) [英] MongoDb Select Query Issue Whit Regular Expression (Starts whit and Ends Whit)

查看:581
本文介绍了MongoDb Select查询Issue Whit正则表达式(以whit结尾,以Whits结尾)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来验证这样的字符串:

I need a regular expression to validate a String like this:

1678; 1678; 1678; 1678和1; 0; 1; 1; 0; 1

1678;1678;1678;1678 and 1;0;1;1;0;1

我尝试使用此模式:

db.getCollection('CollectionName').find(
    {
    "magnitude": /^[1678][1678]$/,
    "flag": /^[1][1]$/
    }
)

但它不起作用,我尝试了这两种模式,它们分别工作,但不能同时工作

but it doesnt works, i try this two patterns that works separate but not both at the same time

db.getCollection('CollectionName').find(
    {
        "magnitude": /[1678]$/,
        "flag": /[1]$/
    }
)

db.getCollection('CollectionName').find(
    {
       "magnitude": /^[1678]/,
       "flag": /^[1]/
    }
)

我没有在SQL中找到任何类似*的字符

I didnt find any character like * in SQL to use in this

我正在使用robomongo 1.0.0进行查询

I am using robomongo 1.0.0 for querys

我会很感激

预先感谢

推荐答案

如果要匹配多个;分隔的字符串,请使用捕获组.

If you want to match more than one ; separated strings then use capturing groups.

db.getCollection('CollectionName').find(
    {
       "magnitude": /^1678(;1678)*$/,
       "flag": /^[01](;[01])*$/
    }
)

(;1678)*与字符串;1678匹配零次或更多次.

(;1678)* matches the string ;1678, zero or more times.

[01]匹配0 OR 1

这篇关于MongoDb Select查询Issue Whit正则表达式(以whit结尾,以Whits结尾)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆