Replacing Dots in Strings with JavaScript
Problem:
You wish to remove all instances of periods (.) from a JavaScript string. For example, transforming "okay.this.is.a.string" into "okay this is a string."
Attempted Solution:
mystring.replace(/./g,' ');
However, this attempt replaces all characters in the string with spaces.
Solution:
The period (.) has a special meaning in regular expressions, representing "any character." To match a literal period, it must be escaped with a backslash:
mystring = mystring.replace(/./g,' ');
The above is the detailed content of How to Replace Dots in Strings with JavaScript Without Replacing All Characters?. For more information, please follow other related articles on the PHP Chinese website!