Fix index_of_pattern for contexts with multiple match