fix bug in which matches at the end of string get ignored