<script>
document.getElementById('aaa').onclick=function(){
var s=""
for(var i=0i<this.options.lengthi++){
if(this.options[i].selected){
if(s)s+=","
s+=this.options[i].value
}
}
document.getElementById("bbb").value = s
}
</script>
var fn = function(str, i) {if ("" == str) {
return ""
}
var f = str[0]
if (/^\d$/.test(f)) {
if (i == 2) {
return f + "," + fn(str.substring(1), 0)
} else {
return f + fn(str.substring(1), ++i)
}
} else {
return f + fn(str.substring(1), i)
}
}
console.log(fn("12d34a56s7sd5f6a",0))