to match and not to match

brent mojavekid at
Fri Aug 30 19:16:04 EDT 2002

I'm trying to parse a large directory listing of instances where the
word "Psych" shows up; this code snippet has been working great for

filew = open('directory.txt', 'w')
done = 0

while not done:

        aLine = file.readline()

        if aLine != "":

                if'Psych[^irsmo]', aLine):
                        r = r + 1
                        print '.',
                done = 1


My problem is that there are instances where a match needs to not be a
match ... cases where the word Psych shows up in the same line along
with another instance like Psychiatry, psychology. How can I modify
this search to match on a single Psych,  but not if another instance
of Psych* shows up? Any help would be greatly appreciated.


More information about the Python-list mailing list