The key difference is that the REGEX literal cannot accept dynamic input, i.e. from variables, while the constructor can, because the pattern is specified as a string.
Suppose you want to combine one or more words from an array in a string:
var words = ['foo', 'bar', 'orange', 'platypus']; var str = "Foo something nice orange what a lovely platypus"; str.match(new RegExp('\\b('+words.join('|')+')\\b'));
This would not be possible with the literal /pattern/ , since everything that is between two slashes is interpreted literally.
Also note the need for double escape commands (i.e., \\ ) when specifying patterns this way, because we do this in a line - the first backslash must be escaped by the second, so one of them does it in the pattern. If there was only one, it would be interpreted by the JS parser as an escape character and be deleted.
source share