Quantcast
Channel: How do I do a case-insensitive string comparison? - Stack Overflow
Viewing all articles
Browse latest Browse all 16

Answer by Shiwangi for How do I do a case-insensitive string comparison?

$
0
0

I saw this solution here using regex.

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

It works well with accents

In [42]: if re.search("ê","ê", re.IGNORECASE):....:        print(1)....:1

However, it doesn't work with unicode characters case-insensitive. Thank you @Rhymoid for pointing out that as my understanding was that it needs the exact symbol, for the case to be true. The output is as follows:

In [36]: "ß".lower()Out[36]: 'ß'In [37]: "ß".upper()Out[37]: 'SS'In [38]: "ß".upper().lower()Out[38]: 'ss'In [39]: if re.search("ß","ßß", re.IGNORECASE):....:        print(1)....:1In [40]: if re.search("SS","ßß", re.IGNORECASE):....:        print(1)....:In [41]: if re.search("ß","SS", re.IGNORECASE):....:        print(1)....:

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>