问题
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