0

I'm looking for a function in Python that checks whether a string A is contained in a string B for any combination of upper/lower characters of both strings.

Example:

a = 'uaUa'
b = 'this is a longer string containing uaua'

checkString (a, b) returns True because a is contained in b.

kylieCatt
  • 10,672
  • 5
  • 43
  • 51
DaniPaniz
  • 1,058
  • 2
  • 13
  • 24
  • A form of this question has been asked many times so I can going to vote to close it search for substring matching - I will note that a.lower() and b.lower() will help – PyNEwbie May 19 '14 at 14:29
  • ups sorry. I made a quick search but I couldn't find anything. thanks! – DaniPaniz May 19 '14 at 14:39

3 Answers3

4
def checkString(a, b):
    return a.lower() in b.lower()
endragor
  • 368
  • 2
  • 9
0

Try https://docs.python.org/2/library/re.html#re.search

>>> import re
>>> a = 'uaUa' 
>>> b = 'this is a longer string containing uaua'
>>> print bool( re.search(a, b, re.IGNORECASE) )
True
Nick
  • 314
  • 1
  • 4
0

You could just convert both strings to lowercase (for instance) with the ".lower()" method, and then use the standard find methods of Python's string functionalities.

MultiVAC
  • 354
  • 1
  • 10