When using the constructor, RegExpyou do not provide delimiters, and the flags go in the second argument.
var id = "1234";
regex = new RegExp(id, "i");
However, RegExp just for 1234s idoesn't really make sense. Use instead indexOf().
However, perhaps you really wanted to match the numbers surrounded \. In this case, leave them there.
source
share