Regular expressions using re

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blindlemonsam
    New Member
    • Jan 2008
    • 6

    Regular expressions using re

    Python 2.5
    Hi all, can anybody tell me how to say "if a jpeg file does NOT have 'gallery_' in the first bit" using the python re module. Something like this:
    [code=python]
    re.compile('^ga llery_[^|]{1,256}.jp[e]{0,1}g$', re.I)
    [/code]
    The problem seems to be with the first bit "^gallery_" which is wrong, it just returns all the files that do have "gallery_" in the first bit.
  • drumma5
    New Member
    • Apr 2008
    • 1

    #2
    I wrote a function for you just to show a way you could do it: (I hope this answers what you were wondering about)
    Code:
    def find_match(str):
        if not re.match('^gallery_[^|]{1,256}\.jpe?g', str):
            print 'it did NOT match';
        else:
            print 'it matched';

    Comment

    Working...