import re def is_hmmmm(string): pattern = r'^hm{2,}(\.{3,}|)$' return re.search(pattern, string)