What are Regular Expressions in MongoDB?

Regular Expressions are frequently used in all languages to search for a pattern or word in any string. MongoDB also provides functionality for regular expression for string pattern matching using the $regex operator. MongoDB uses PCRE(Perl Compatible Regular Expression) as a regular expression language. Unlike text search, we do not need to do any configuration or command to use regular expressions. Use the following code for regular expression find query.

db.collection.find({fieldname: {$regex: “value”}})

To make case insensitive add $options: “$i”