title: Removing lines from a text file using python and regular expressions
body: <p>I have some text files, and I want to remove all lines that begin with the asterisk (“*”).</p>
  
  <p>Made-up example:</p>
  
  <pre><code>words
  *remove me
  words
  words
  *remove me 
  </code></pre>
  
  <p>My current code fails. It follows below:</p>
  
  <pre><code>import re
  
  program = open(program_path, "r")
  program_contents = program.readlines()
  program.close() 
  
  new_contents = []
  pattern = r"[^*.]"
  for line in program_contents:
      match = re.findall(pattern, line, re.DOTALL)
      if match.group(0):
          new_contents.append(re.sub(pattern, "", line, re.DOTALL))
      else:
          new_contents.append(line)
  
  print new_contents
  </code></pre>
  
  <p>This produces ['', '', '', '', '', '', '<em>', '', '</em>', '', '*', ''], which is no goo.</p>
  
  <p>I’m very much a python novice, but I’m eager to learn. And I’ll eventually bundle this into a function (right now I’m just trying to figure it out in an ipython notebook).</p>
  
  <p>Thanks for the help! </p>