var str = '1000,900,1000,900,900,900,1000,-100,3456,3456,435,3456'; console.log(str.match(/(-*\d+,*){3}(-*\d+)/g).map((el,i)=>(i+1+','+el).split(',')));