By using replace() function on any string variable, we can replace character(s) with another character(s). But by default it will only replace the first occurrence. What if we want to replace all occurrence? Here I’ll show you how.
Just watch this two video tutorials:
We can do it by using regular expression. For example, I have a string variable like this:
var myText = "This Is my Text. TEXT text UPPERCASE lowercase.";
Then after I call below function,
myText.replace( /[t|e|s]/gi , "x" );
Here is the result:
"xhix Ix my xxxx. xxXx xxxx UPPxRCAxx lowxrcaxx."