Pattern: Invalid regular expression in RegExp constructor
Issue: -
Using an invalid pattern in RegExp constructor causes a runtime SyntaxError when the code is executed, unlike regexp literals which fail at parse time. Invalid patterns include incorrect syntax or invalid flags.
Example of incorrect code:
RegExp('[');
RegExp('.', 'z');
new RegExp('\\');
new RegExp('[a-z', 'g');
RegExp('foo', 'bar');
Example of correct code:
RegExp('.');
new RegExp('[a-z]');
RegExp(pattern, 'g');
new RegExp(/foo/g);
this.RegExp('['); // Not creating RegExp