Learn from the pattern first, then slide it past whatever already matched without ever moving back in the text.
This interactive visualization needs JavaScript.