I've been trying to teach myself regular expressions as I've mostly somehow avoided it so far.
However I have a puzzler.
Here's the code.
listostuff = [ "crustybread", "rusty nail", "grust0", "superrust"]
for item in listostuff:
result = True if re.match(r'[a-z]+rust[a-z0-9\s \t\s+]+', item) else False
print item, result
rusty nail False
You need to make sure the pattern allows matching 0 or more letters at the beginning, replace
re.match(r'[a-z]*rust[a-z0-9\s]+', item) ^
re.match only anchors the match at the start of the string, add
$ at the end of the pattern if you want the whole input string to match your pattern.
See the regex demo.