I’m trying to create a regex to replace comma by a dot and only have one dot and delete all of the other ones, for example:
0,23433,222
Should return
0.23433222
Or
123,33
Should return
123.33
>Solution :
Just replace the first comma with a point and then remove all remaining commas. No regular expressions needed:
const str = "0,23433,222";
const res = str.replace(",", ".").replaceAll(",", "");
console.log(res);