Lets say I have a list of strings,
string_lst = [\'fun\', \'dum\', \'sun\', \'gum\']
I want to make a regular expression, where at a point
You should make sure to escape the strings correctly before combining into a regex
>>> import re >>> string_lst = ['fun', 'dum', 'sun', 'gum'] >>> x = "I love to have fun." >>> regex = re.compile("(?=(" + "|".join(map(re.escape, string_lst)) + "))") >>> re.findall(regex, x) ['fun']