var arr = '5*(6+9*5)*20'.replace(/^(\d+)\*/i,"$1,").replace(/\*(\d+)$/i,",$1").split(","); for(var i=0;i<arr.length; i++){arr[i]=eval(arr[i]);} alert(arr.join(",\n"))