Reputation: 110
var str = 'TEST, STRING'; var regex = new RegExp('^(.*)('+str+')(.*)$/i'); console.log(regex);
Output
/^(.*)(TEST, STRING)(.*)$\/i/
But I need the following output:
/^(.*)(TEST, STRING)(.*)$\/i
Upvotes: 2
Views: 610
Reputation: 87203
The flags should be the second parameter to the RegExp constructor.
RegExp
new RegExp('^(.*)(' + str + ')(.*)$', 'i'); ^ ^^^
The syntax of RegExp constructor is
new RegExp(pattern[, flags])
Upvotes: 4