How to match a string consisting special character like hyphen and spaces

隐身守侯 提交于 2020-04-07 08:12:27

问题


I have a string as:

word : 'A-Scan Ultrasonic'

How to match this with :

   'A Scan Ultrasonic'

I have tried my luck as

{word:{$regex:".*A Scan Ultrasonic.*",$options: 'i'}}

But this doesn't fetch any result

May I know how this can be matched , any help is appreciated , TIA


回答1:


It's actually no mongo thing, you should use proper regex. Try with this:

{ name: { $regex: /.*A(-|\s)Scan(-|\s)Ultrasonic.*/}}


来源:https://stackoverflow.com/questions/60810426/how-to-match-a-string-consisting-special-character-like-hyphen-and-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!