title: Regex to Match #Comment Not Working Correctly
body: <p>I'm trying to write a regular expression which will detect the following type of comment:</p>
  
  <ul>
  <li>Begins with a single <code>#</code> and continues until the end of the line</li>
  <li>Will treat any escaped <code>#</code> (<code>\#</code>) as ordinary text (thus, it will not make anything subsequent to it a comment if it wasn't one already)</li>
  </ul>
  
  <p>Using <a href="http://www.regexr.com/" rel="nofollow">this tool</a>, I came up with the following regex to achieve this:</p>
  
  <pre><code>(?!\\)(#(.*)\n)
  </code></pre>
  
  <p>Using it in global mode, I tested it on the following input text, which is pretty self-explanatory:</p>
  
  <pre><code>#This comment should be caught, and any embedded #s or escaped \#s should also be
  While none of this line this should be \#\#\#
  </code></pre>
  
  <p>Now, the matches for that regex are:</p>
  
  <ul>
  <li>The entire first line</li>
  <li>Everything on the second line starting from the first <code>#</code> but not including the <code>\</code> before it</li>
  </ul>
  
  <p>Obviously, this is too much - nothing on that second line should be captured. What should I change to make it work how I want it to?</p>