An invalid pattern in a regular expression literal results in a SyntaxError when the code is parsed,
but an invalid string in a RegExp
constructor throws a SyntaxError only when the code is executed.
To avoid unwated runtime errors, consider refactoring the regex patterns.
// Runtime error: unterminated character class
RegExp('[')
// Invalid regular expression flag: z
RegExp('.', 'z')
// \ at end of pattern
new RegExp('\\')
RegExp('[a-zA-Z0-9]')
RegExp('.', 'g')
new RegExp('\d+')