KcH
KcH

Reputation: 3502

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

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

Upvotes: 0

Views: 1087

Answers (1)

Raymond Reddington
Raymond Reddington

Reputation: 1837

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

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

Upvotes: 1

Related Questions