Fixed an error if the pattern is in the beginning of the text