By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

Regular expressions using re

P: 6
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:
Expand|Select|Wrap|Line Numbers
  1. re.compile('^gallery_[^|]{1,256}.jp[e]{0,1}g$', re.I)
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.
Apr 3 '08 #1
Share this Question
Share on Google+
1 Reply

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

Post your reply

Sign in to post your reply or Sign up for a free account.