Case-insensitive string comparison

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Apr 15 11:13:55 EDT 2003


Alex Martelli <aleax at aleax.it> wrote in 
news:jJUma.23762$T34.707989 at news2.tin.it:

> import re
listofnames = [re.escape(n) for n in listofnames]
> namesre = re.compile('(%s)'%')|('.join(listofnames), re.I)
> 
> for m in namesre.finditer(astring):
>     dosomething(astring, listofnames[m.lastindex-1])
> 
> 

I suggest adding the line above to avoid any nasty surprises (or use a 
different variable if you don't want to clobber listofnames).


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list