/[,s]+|[,s]+/g var str= "your string here"; //this will be new string after replace str = str.replace(/[,s]+|[,s]+/g, 'your string here');