problem with regex

x-herbert i.steinhardt at web.de
Fri Nov 22 05:19:18 EST 2002


Hi,

I have a problem with the regex in python:

I will e.g. only find the word eMail in a string. Her is a part of my code...
.....................
key = "eMail"
i = ".....bla bla XXXX ..."  #see below for XXXX...
regkey = "\\b"+key+"\\b"     # for find key alone
regex = re.compile(regkey)
result = regex.search(i)
if result:
    print "find"
else:
    print "find not"
.......................
Result:
XXXX:       print:
eMail       find   # o.k. ;-)
eMailNews   find not
eMail_News  find not
eMail-News  find # upps why!!!!!!!!!!!!!!!!
eMail*News  find # upps why!!!!!!!!!!!!!!!!
eMail?News  find # upps why!!!!!!!!!!!!!!!!
eMail#News  find # upps why!!!!!!!!!!!!!!!!
...etc.

I think, the regkey = "\beMail\b" find this word alone.... ?????

Thanks!

Ingolf



More information about the Python-list mailing list