first = line.match( /(?:(0|zero)|(1|one) ... (9|nine))/) last = line.match(/.*(?:(0|zero)|(1|one) ... (9|nine))/) indexOfGroupMatched = ([_, ...groups]) => groups.findIndex(x => x != undefined) num = +[first, last].map(indexOfGroupMatched).join('')