I need to replace the decimal separator in a string, and the decimal separators could be a dot . (e.g. English) or a comma , (e.g. German). So I have the variable sep for containing the separator string.
To convert the English-based decimal separator, I do the following replacement, but I got ,dd,dd rather than 120,dd:
var sep = '.';
var numberStr = '120.31';
numberStr = numberStr.replace(new RegExp(sep + '\\d{2}', 'g'), ',dd');
console.log(numberStr);
Does anyone know where I went wrong?