匹配所有搜索词的正则表达式 [英] Regular expression to match all search terms

查看:44
本文介绍了匹配所有搜索词的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来匹配一组搜索词中的所有词.如果用户输入bat sun",那么我需要匹配所有单词以bat"开头且以sun"开头的文本条目.因此,Sunday Batman"和Batmobile sundance"应该都匹配,但Sunday"或Batman"不匹配,因为并非所有搜索词都匹配.

I need a regular expression that will match on all terms in a set of search terms. If the user types "bat sun" then I need to match any text entries that have words starting with "bat" AND starting with "sun". So, "Sunday Batman" and "Batmobile sundance" should both match, but "Sunday" or "Batman" won't match because not all search terms are matched.

我正在使用 MongoDB(官方 C# 驱动程序)中的表达式来支持搜索.

I'm using the expression within MongoDB (official C# driver) to support searching.

谢谢!

推荐答案

如果你真的想使用正则表达式,可能像下面这样的正则表达式:

Probably a regex like below if you really want to use regex:

(?=.*\bsun)(?=.*\bbat).*

当然你想让它忽略大小写.

Of course you want to make it ignore case.

这篇关于匹配所有搜索词的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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