The following statement in JavaScript works as expected:
var s1 = s2.replace(/ /gi, '_'); //replace all spaces by the character _
However, to replace all occurrences of the character . by the character _, I have:
var s1 = s2.replace(/./gi, '_');
But the result is a string entirely filled with the character _
Why and how to replace . by _ using JavaScript?
The . character in a regex will match everything. You need to escape it, since you want a literal period character: