Fix the problem when no hit at the end of the string.