I want to find if there is a sub-string of the string "chef" but in order in another given string with length > 1.
So basically we want strings ch, he, ef, che, hef or chef to exist in the given string.
Here we have ef which is part of ''chef'' so it is a valid string.
Here we have fh which characters exist in 'chef' but the sequence is incorrect so it is invalid.
I have this code that works but here adding substrings manually is easy as the string 'chef' has quite fewer possibilities but I want a code that will work for any given string.
import re pattern = r"(ch|he|ef|che|hef|chef)" s = input() res = re.search(pattern, s) if bool(res): print('YES') else: print('NO')
P.S. Im sorry if this question was already asked and solved, I was unable to find it.