demo('-30--15') // => {min: -30, max: -15} function demo(data) { const list = data.replace(/^(.*?)(-)(-?\d+)$/, '$1,$3').split(',') return { min: Math.min(...list), max: Math.max(...list) } }