[Tutor] function to ignore case
Reggie Dugard
reggie@merfinllc.com
Wed Jul 30 13:21:54 2003
Matt,
You don't mention what version of python you're using, but assuming
you're using a release that's not too old, there are a couple of ways to
do what you want.
You can use regular expression searching (re module) and specify the
IGNORECASE flag:
>>> import re
>>> m = re.search('multi', 'A mUltiCased string', re.IGNORECASE)
>>> bool(m)
True
>>>
OR
You can convert both strings to a common case using the upper() or
lower() string methods, before you do the comparison:
>>> s = 'A mUltiCased string'.lower()
>>> s
'a multicased string'
>>> s.find('multi')
2
>>>
Hope this puts you on the right track
On Wed, 2003-07-30 at 10:05, Matt Richardson wrote:
> Can someone point me to a function that will ignore case when searching
> for a string? This is how my 17 month old must feel--knowing what you
> want but not how to say it :)
>
> Matt
--
Reggie