You can pass a function replaceand skip the first match as follows:
var i = 0;
value.replace(/[\.\%]/g, function(match) {
return match === "." ? (i++ === 0 ? '.' : '') : '';
});
Here is a standalone version without external variables:
value.replace(/[\.\%]/g, function(match, offset, all) {
return match === "." ? (all.indexOf(".") === offset ? '.' : '') : '';
})
offset, replace() ., (all). , .. , ., ''. % ''.
:
4.5667.444... == > 4.56667444
% 4.5667.444... == > 4.5667444
: http://jsbin.com/xuzoyud/5/