var mystring = "this.is.a.test";
mystring = mystring.replace(/./g, "X");
console.log(mystring);
I expect the output of thisXisXaXtest
but my log show XXXXXXXXXXXXXX
var mystring = "this.is.a.test";
mystring = mystring.replace(/./g, "X");
console.log(mystring);
I expect the output of thisXisXaXtest
but my log show XXXXXXXXXXXXXX
.
is special character in regex ( which means match anything except new line ) you need to escape it
var mystring = "this.is.a.test";
mystring = mystring.replace(/\./g, "X");
console.log(mystring);
.
matches every character other than newlines. To use it how you are intending, it needs to be escaped: \.
.