How to match a substring in a string, ignoring case

后端 未结 8 1761
既然无缘
既然无缘 2020-12-08 12:58

I\'m looking for ignore case string comparison in Python.

I tried with:

if line.find(\'mandy\') >= 0:

but no success for ignore

相关标签:
8条回答
  • 2020-12-08 13:28
    import re
    if re.search('(?i)Mandy Pande:', line):
        ...
    
    0 讨论(0)
  • 2020-12-08 13:30

    There's another post here. Try looking at this.

    BTW, you're looking for the .lower() method:

    string1 = "hi"
    string2 = "HI"
    if string1.lower() == string2.lower():
        print "Equals!"
    else:
        print "Different!"
    
    0 讨论(0)
提交回复
热议问题