As the title states, I need to relace all occurrences of the $ sign in a string variable with an underscore.
I have tried:
str.replace(new RegExp(\'$
The $ in RegExp is a special character, so you need to escape it with backslash.
$
new_str = str.replace(new RegExp('\\$', 'g'), '_');
however, in JS you can use the simpler syntax
new_str = str.replace(/\$/g, '_');