I want to remove special characters from a string and replace them with the _ character.
_
For example:
string = \"img_realtime_tr~ading3$
string = string.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_');
Alternatively, to change all characters except numbers and letters, try:
string = string.replace(/[^a-zA-Z0-9]/g,'_');
string = string.replace(/[\W_]/g, "_");