[Tutor] Regex to find files ending with one of a given set of extensions

Dayo Adewunmi contactdayo at gmail.com
Sun Feb 21 18:23:04 CET 2010


Hi all

I'm trying use regex to match image formats:

import re

def findImageFiles():
    imageRx = re.compile('\.jpe?g$|\.png$|\.gif$|\.tiff?$', re.I)

    someFiles = 
["sdfinsf.png","dsiasd.dgf","wecn.GIF","iewijiefi.jPg","iasjasd.py"]

    findImages = imageRx(someFiles)

    print "START: %s" %(findImages.start())
    print "GROUP: %s" %(findImages.group())


def main():
    findImageFiles()


if __name__ == "__main__":
    main()


here's the traceback:

$ python test.py
Traceback (most recent call last):
  File "test.py", line 25, in <module>
    main()
  File "test.py", line 21, in main
    findImageFiles()
  File "test.py", line 14, in findImageFiles
    findImages = imageRx(someFiles)
TypeError: '_sre.SRE_Pattern' object is not callable

  i'm new with regexing, please help.

Thanks

Dayo


More information about the Tutor mailing list