Pattern searching
Pattern searching is an algorithm to find out the location of a string in another string. This process is usually used in a word processor (such as Notepad or Sublime Text) to find a word position in a document. Let's look at the sentence—the quick brown fox jumps over the lazy dog. If we need to find out the position of the word the, we can use this algorithm and pass the as the pattern.
Note
You might be confused with Regular Expression (regex) and pattern searching, the latter of which we are going to discuss in this section. With regex, we can check if a string satisfies a given pattern, while in this section we'll be discovering how to find a string (called a pattern) in another string. If you're interested in learning about RegEx in C++, you can go to http://www.cplusplus.com/reference/regex/.
To find the position of the pattern in a string, we have to iterate through the string's elements from the beginning until the last possible element. In our preceding example,...