import re def getName(strl): pattern = re.compile('the name is (.*),') result = pattern.findall(strl) return result for i in getName(strl): print(i)