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

How do I replace ", ," with ","

My string is as follows "Increase in housing cost, Create sense of Financial security, Reduced Travel, ,Happiness for Family, Financial Security".
I want to remove the space and extra comma in the string using JavaScript. So the final string should be "Increase in housing cost, Create sense of Financial security, Reduced Travel, Happiness for Family, Financial Security"
The string is coming from a variable "myString"
I tried using
myString = myString.replace(", ,",","); but it does not work.

>Solution :

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

match , and , with whitespace (or none) in between them

var reg = /,\s*,/g
console.log("Increase in housing cost, Create sense of Financial security, Reduced Travel, ,Happiness for Family, Financial Security".replace(reg, ', '))
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