我有一个包含1000条记录的带有字符串列的集合。
我正在使用Jongo API查询mongodb。
我需要找到匹配的记录,其中列字符串以字母“ AB”开头,以斜杠“ /”结尾
在查询上需要帮助,以选择相同的查询。
谢谢。
我假设您知道如何在Jongo API中使用正则表达式进行查询,而只是在寻找必要的正则表达式来执行此操作?
如果是这样,则此正则表达式将找到以'AB'开头(区分大小写),后跟任意数量的其他字符,然后以正斜杠('/')结尾的任何字符串:
^AB.*\/$
^ - matches the start of the string
AB - matches the string 'AB' exactly
.* - matches any character ('.') any number of times ('*')
\/ - matches the literal character '/' (backslash is the escape character)
$ - matches the end of the string
如果您刚开始使用regex,我强烈建议您使用Regex 101网站,这是一个测试regex的绝佳沙盒,并解释了表达式的每一步,从而使调试变得更加简单。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句