proposed solution for issue #414 - from Vitaly

Assuming my analysis was correct, here is my solution to the problem.

1. There is no look-ahead or state ("pattern" variable): each iteration start with the new sequence - easier to understand the code, as for me.
2. no tiny Strings creation ("pattern" variable again).
3. a bit more comments
4. more tests

Thanks.

ps. just saw that it used tabs.. sorry, please let me know if you need spaces