Newbie: searching an English dictionary for a reg exp

^^@++ ballsacks at xtra.co.enzed
Mon Dec 3 01:40:59 EST 2001


On Sun, 2 Dec 2001 13:54:24 -0800, "Eugene" <import binascii; print
binascii.a2b_base64('ZXVnZW5lQGlzb21lZGlhLmNvbQ==')> wrote:

Oops, looks like I spoke too soon with my last post.
The matches aren't working properly, in that it seems to be finding
too many incorrect matches:

def searchfor(regpattern):
    print "Searching for",regpattern,
    matchcount = 0
    reg = re.compile(regpattern, re.I)
    m = ""
    for word in dictionary:
        m = reg.match(word)
        if m:
            outfile.write(m.group()+' ')
            matchcount += 1
            
    print "Found",matchcount
    return matchcount

Produces:
Read 1187 words from the dictionary
Read 1 clues from clues.txt
Searching for abac. Found 14

Now, in my dictionary there are only 2 words that would match that
criteria - abaca and aback, right? It seems to be returning what is I
guess (abac)*:
dictionary = 
...
Ababua
abac
abaca
abacate
abacay
abacinate
abacination
abaciscus
abacist
aback
abactinal
abactinally
abaction
abactor
abaculus
abacus
Abadite
...

I get the feeling I'm barking up the wrong tree by using m.group().
All I want is the word that matches! IMO the doco for MatchObject
(match-objects.html) is useless (or maybe I am). 

Thanks for any help

-Matt



More information about the Python-list mailing list