Finds the first index based on a regex match
@param   {RegExp} regex a regex object
@param   {Number} index optional starting index
@returns {Number} the index of the match
function indexOfMatch(string, regex, index) {
  const str = index !== null ? string.substring(index) : string;
  const matches = str.match(regex);
  return matches ? str.indexOf(matches[0]) + index : -1;
}