Zoltán
Zoltán

Reputation: 22146

Mongo regex pattern syntax match slash

I'm trying to search for urls that start with a certain format, e.g. http://stackoverflow.com/questions using the mongo pattern syntax. I've tried

db.mycollection.find({"link": /^http://stackoverflow.com/questions/})

which obviously didn't work because the / character is a delimiter. I've also tried escaping slashes with backslashes:

db.mycollection.find({"link": /^http:\/\/stackoverflow\.com\/questions/})

but that gave me a syntax error. So how do I match slashes?

Upvotes: 2

Views: 7162

Answers (1)

Zoltán
Zoltán

Reputation: 22146

It turns out that escaping slashes with backslashes only doesn't work in MongoHub. It works as expected in the console, i.e.

db.mycollection.find({"link": /^http:\/\/stackoverflow\.com\/questions/})

Upvotes: 3

Related Questions