fixed crash when pattern appears from head/tail of text