You aren't using RegExp
constructor as it should have been used.
It is like this:
new RegExp("pattern without / at the beginning an end","flags");
/pattern/flags
is literal form of writing a regex in js, but it is different in RegExp constructor.