[Tutor] Regexp Not Matching on Numbers?

Gooch, John John.Gooch at echostar.com
Tue Dec 14 18:15:32 CET 2004

This is weird. I have a script that checks walks through directories, checks
to see if their name matches a certain format ( regular expression ), and
then prints out what it finds. However, it refuses to ever match on numbers
unless the regexp is ".*". So far I have tried the following regular
and more...

Here is an example of the output:
No Match on partners80_access_log.1102723200
Checking on type=<type 'str'> Name = some_access_log.1102896000

Here is the code:
import os,sys
import re
#define the file mask to identify web log files
regexp = re.compile( r"\." )

startdir = "C:/Documents and Settings/John.Gooch/My Documents/chaser/"
#define global functions
def delFile(arg, dirname, names):
    found = 0
    for name in names:
        print "Checking on type="+str(type( name ) )+" Name = "+str(name)
        matches = re.compile(r"([\w]+)").match( name )
        if matches:
            print "Match on "+str(matches.groups()) 
            found = 1
            print "No Match on "+name
    if not found:
        print "No matches found in "+dirname
        print "Match found in "+dirname
os.path.walk( startdir, delFile, "" )

Any thoughts?

More information about the Tutor mailing list