Python match a string with regex

前端 未结 6 521
天命终不由人
天命终不由人 2020-12-17 07:38

I need a python regular expression to check if a word is present in a string. The string is separated by commas, potentially.

So for example,

line =          


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 08:00

    As everyone else has mentioned it is better to use the "in" operator, it can also act on lists:

    line = "This,is,a,sample,string"
    lst = ['This', 'sample']
    for i in lst:
         i in line
    
    >> True
    >> True
    

提交回复
热议问题