Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex to replace character in Javascript

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading