Here's a simple algorithm for doing that. fyi, this is how a Regex Engine works for constant strings.

1. Start looking from the left (position 0)
2. See if the letter matches the first letter in...