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.

2
  • 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, 2014 at 14:29
  • ups sorry. I made a quick search but I couldn't find anything. thanks!
    – DaniPaniz
    May 19, 2014 at 14:39

3 Answers 3

4
def checkString(a, b):
    return a.lower() in b.lower()
0
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
3
  • 2
    why use regular expressions for something this simple? May 19, 2014 at 14:31
  • actually I thought about using reg expressions but I didn't know the function bool() and IGNORECASE. superquick! thanks :)
    – DaniPaniz
    May 19, 2014 at 14:35
  • Glad it was helpful. Happy parsing!
    – Nick
    May 19, 2014 at 14:37
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.