How to match any string from a list of strings in regular expressions in python?

后端 未结 5 1322
深忆病人
深忆病人 2020-12-01 10:50

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

5条回答
  •  无人及你
    2020-12-01 11:14

    In line with @vks reply - I feel this actually does the comeplete task..

    finds = re.findall(r"(?=(\b" + '\\b|\\b'.join(string_lst) + r"\b))", x)
    

    Adding word boundary completes the task!

提交回复
热议问题