move start index and end index inside regex.exec loop