Passing regex modifier options to RegExp object

You need to pass the second parameter:

var r = new RegExp(keyword, "i");

You will also need to escape any special characters in the string to prevent regex injection attacks.

Leave a Comment