How to match a substring in a string, ignoring case How to match a substring in a string, ignoring case python python

How to match a substring in a string, ignoring case


If you don't want to use str.lower(), you can use a regular expression:

import reif re.search('mandy', 'Mandy Pande', re.IGNORECASE):    # Is True


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!"


Try:

if haystackstr.lower().find(needlestr.lower()) != -1:  # True