Handle reset after failure of first match; keep track of start of partial match and backtrack to the item after that if the current match fails.

Add test cases.