SyntaxFix
Write A Post
Hire A Developer
Questions
You should use double slash:
var regex = new RegExp("\\?", "g");
Why? because in JavaScript the \ is also used to escape characters in strings, so: "\?" becomes: "?"
\
"?"
And "\\?", becomes "\?"
"\\?"
"\?"