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 :
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, ', '))