import re # '*' replaces the no. of occurrence of a character. p = re.compile('so*') print(p.findall("softhuntsamsungsolonaspidersonysorry"))