I am trying to replace all complete stops in the letter with the x symbol - for example, " my.email@email.com " will become "myxemail @emailxcom". Email is set to string.
My problem is that it does not replace only complete stops, it replaces every character, so I just get the string x.
I can get it to work with one full stop, so I assume that I am mistaken in the global part of the instance. Here is my code:
let re = ".";
let new = email.replace(/re/gi, "x");
I also tried
re = /./gi;
new = email.replace(re, "x");
If someone can shed light, I would be very grateful for this, I have lingered on this for so long and cannot understand where I am mistaken.
** Edit: Oops, my new variable is actually called newemail, the new keyword did not cause a problem!
source
share