$regex not working

regex not working for string “ahs():+ahs” let us know how we can search with . dot or other specials char
db.getCollection.find({“name” : { $regex :".ahs()- ,’ : +ahs.", $options : “i”}})

For below query we are getting result.

db.getCollection(‘parameter’).find({“name” : { $regex :".ahs().", $

Special characters in regular expressions have to be escaped if you want to search for them.

That’s not specific to MongoDB regular expressions. Try using \ (backslash) character before characters you want to match literally (like .).

Asya

Hi Asya,
Thanks for replying back it is required to search a string which has. Dot in both either search criteria and database value.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.