简体   繁体   English

从起始字母搜索的Javascript正则表达式?

[英]Javascript regular expression for search from starting letter?

I want add search functionality.我想添加搜索功能。 I need to search any document by starting letter.我需要通过首字母搜索任何文档。

Suppose, we have to some document like-假设,我们必须有一些文件,比如 -

Apple Industry
Samsung Industry
Xioami Industry
Ahua Industry
Sumatech Industry

You need to add the startWith<\/code> modifier to your regex.您需要将startWith<\/code>修饰符添加到您的正则表达式。 I'm not sure how this object gets converted to the regex, but here you go:我不确定这个对象是如何转换为正则表达式的,但是你去吧:

{ Industry: { '$regex': '^a.*', '$options': 'i' } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM