Javascript: Regex capturing group iteration