A regular expression literal creates a pattern for matching strings, using forward slashes as delimiters: /test/. Add flags after the closing slash, as in /test/ig. section 12.2.1 section 12.7
Prefer a literal when the pattern is fixed: backslashes are easier to read here than inside a string, where they must be escaped. Use the RegExp constructor when assembling a pattern dynamically; take care with arbitrary user-provided patterns, which can consume excessive CPU. section 12.2.1
const pattern = /test/;
See the minimal slash-delimited literal syntax. section 12.2.1


