A small question about the pattern matching of data structure and string

A little doubt on the intermediate textbook of programmers in the soft exam:

in the worst case, each unsuccessful match is the last character of the pattern string, which is not equal to the corresponding character in the main string, then the starting position of the new run in the main string is i-m+2.

where did this i-m+2 come from?
according to the simple string matching algorithm, it is not successful. The starting position of the next trip should be the next character of the main string.

assume that the main string is S, the length is n, the pattern string is P, and the length is m.
start with S [0], compare S and P
bit by bit, if the match fails, start with S [1], and then S [2] S [3].

Sep.21,2021

the I here should mean: in the worst case, the location subscript of the main string that fails to match the pattern string.

Menu