正则表达式查找字符串以字母开头并以斜杠/结尾 [英] Regular Expression to find string starts with letter and ends with slash /

查看:567
本文介绍了正则表达式查找字符串以字母开头并以斜杠/结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 1000 条记录的集合,其中包含一个字符串列.

I'm having a collection which has 1000 records has a string column.

我使用 Jongo API 查询 mongodb.

I'm using Jongo API for querying mongodb.

我需要找到列字符串以字母AB"开头并以斜杠/"结尾的匹配记录

I need to find the matching records where column string starts with letter "AB" and ends with slash "/"

需要查询帮助才能查询选择相同的内容.

Need help on the query to query to select the same.

谢谢.

推荐答案

我假设您知道如何在 Jongo API 中使用正则表达式进行查询,并且只是在寻找必要的正则表达式来执行此操作?

I'm going to assume you know how to query using Regular Expressions in Jongo API and are just looking for the necessary regex to do so?

如果是这样,此正则表达式将查找任何以AB"开头(区分大小写),后跟任意数量的其他字符,然后以正斜杠(/")结尾的任何字符串:

If so, this regex will find any string that begins 'AB' (case sensitive), is followed by any number of other characters and then ends with forward slash ('/'):

^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 101 网站,这是一个很棒的沙箱测试正则表达式并解释表达式的每个步骤,使调试更简单.

If you're just getting started with regex, I highly recommend the Regex 101 website, it's a fantastic sandbox to test regex in and explains each step of your expression to make debugging much simpler.

这篇关于正则表达式查找字符串以字母开头并以斜杠/结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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