Is it possible to do something like this?
var pattern = /some regex segment/ + /* comment here */ /another segment/;
Or do I have to use new RegExp() syntax and concatenate a string? I’d prefer to use the literal as the code is both more self-evident and concise.
Here is how to create a regular expression without using the regular expression literal syntax. This lets you do arbitrary string manipulation before it becomes a regular expression object:
If you have two regular expression literals, you can in fact concatenate them using this technique:
It’s just more wordy than just having expression one and two being literal strings instead of literal regular expressions.