use a fancy regex to figure out the index