pattern matching, outputs the index of the matches from the begining character