Fix pattern matching logic to consider cases where the pattern is entirely contained in the searched string