title: Regex + Python - Remove all lines beginning with a *
body: <p>I want to remove all lines from a given file that begin with a *. So for example, the following:</p>
  
  <pre><code>* This needs to be gone
  But this line should stay
  *remove 
  * this too
  End
  </code></pre>
  
  <p>Should generate this:</p>
  
  <pre><code>But this line should stay
  End
  </code></pre>
  
  <hr>
  
  <p>What I ultimately need to do is the following: </p>
  
  <ol>
  <li>Remove all text inside parenthesis and brackets (parenthesis/brackets included), </li>
  <li>As mentioned above, remove lines starting with ''. </li>
  </ol>
  
  <p>So far I was able to address #1 with the following: <code>re.sub(r'[.?]|(.*?)', '', fileString)</code>. I tried several things for #2 but always end up removing things I don't want to</p>
  
  <hr>
  
  <p><strong>Solution 1 (no regex)</strong></p>
  
  <pre><code>&gt;&gt;&gt; f = open('path/to/file.txt', 'r')
  &gt;&gt;&gt; [n for n in f.readlines() if not n.startswith('*')]
  </code></pre>
  
  <p><strong>Solution 2 (regex)</strong></p>
  
  <pre><code>&gt;&gt;&gt; s = re.sub(r'(?m)^\*.*\n?', '', s)
  </code></pre>
  
  <p>Thanks everyone for the help.</p>