Creating regexp with special characters

I’m creating a query for mongodb:

function(req, res) {
  var regexp = new RegExp(req.params.title, 'i');

    "title": regexp,
  }).toArray(function(err, array) {

But sometimes the title has a parenthese in it. This gives me the error:

SyntaxError: Invalid regular expression: /cat(22/: Unterminated group
    at new RegExp (unknown source)

The title that is being searched for is cat(22).

What’s the easiest way to make the regex accept parenthesis? Thanks.

Read more here: Source link