You can do this only with javascript:
function arranjar(str){
var partes = str.split(',');
var ultima = partes.pop();
return [partes.join(''), ultima].join(',');
}
arranjar('123,345,678,abc,qualquer,coisa') // dá "123345678abcqualquer,coisa"
To do this with regex is not simpler. But an example would look like this:
function arranjarComRegex(str){
var partes = str.match(/(.*),(.*)/);
var string = partes[1].replace(/,/g, '');
return string + ',' + partes[2];
}
In this case regex (.*),(.*)
captures two groups. In the first capture '123,345,678,abc,qualquer'
where you need to remove the commas with .replace(/,/g, '')
and the second catch group takes the last word, which then needs to be back in the string with string + ',' + partes[2]
.