string.replace(/\./g,'_') is the behavior I would like, but I would prefer not to use the actual regular expression because of this jsperf , which shows that using a string like string.replace('.','_') much faster.
Unfortunately (and this may be disgusting for jsperf, since this in no way becomes obvious), it seems that the replacement will only work in the first match, so it will be identical only
string.replace(/\./,'_')
This is probably enough to invalidate the comparison, because it is only twice as fast (on Webkit) for a simple replace string, but in fact it does only 1/4 of the work, replacing only one period with a space and not all.
There is an obvious approach that
while(string.indexOf('.') !== -1) string = string.replace('.','_');
but is there any better or faster way to achieve this?
source share