title: using regular expressions to exclude characters in a string search?
body: <p>I'm working with a Python 2.7.2 script to find lists of words inside of a text file that I'm using as a master word list. </p>
  
  <p>I am calling the script in a terminal window, inputting any number of regular expressions, and then running the script. </p>
  
  <p>So, if I pass in the two regular expressions "^.....$" and ".*z" it will print every five letter word that contains at least one "z". </p>
  
  <p>What I am trying to do is add another regular expression to EXCLUDE a character from the strings. I would like to print out all words that have five letters, a "z", but -<strong>not</strong>- a "y". </p>
  
  <p>Here is the code:</p>
  
  <pre><code>import re
  import sys
  
  def read_file_to_set(filename):
      words = None
      with open(filename) as f:
          words = [word.lower() for word in f.readlines()]
      return set(words)
  
  def matches_all(word, regexes):
      for regex in regexes:
          if not regex.search(word):
              return False
      return True
  
  if len(sys.argv) &lt; 3:
      print "Needs a source dictionary and a series of regular expressions"
  else:
      source = read_file_to_set(sys.argv[1])
      regexes = [re.compile(arg, re.IGNORECASE)
                 for arg in sys.argv[2:]]
      for word in sorted(source):
          if matches_all(word.rstrip(), regexes):
              print word,
  </code></pre>
  
  <p>What modifiers can I put onto the regular expressions that I pass into the program to allow for me to exclude certain characters from the strings it prints?</p>
  
  <p>If that isn't possible, what needs to be implemented in the code?</p>