Fix a bug relating special patterns '^' and '$'.