title: grep regex to ignore comment at end of line
body: <p>I'm trying to grep through a lot of old PowerBASIC source files in search of a variable, but I'm having trouble getting <code>grep</code> to avoid matching references to the variable in the end-of-line comments.</p>
  
  <p>For example:</p>
  
  <pre><code>ANGLE = 40    ' THIS IS A COMMENT ABOUT ANGLE'S VALUE
  FOO = 3/ANGLE ' ANGLE CAN APPEAR ON RIGHT SIDE AS WELL
  DELTA = 35    ' ANGLE AND DELTA AREN'T FRIENDS
  </code></pre>
  
  <p>Initially I was using:</p>
  
  <pre><code># grep "\bANGLE\b.*'" SRC_FILE.BAS
  </code></pre>
  
  <p>But -- besides ignoring lines with no comments -- it also prints out lines of code which don't use <code>ANGLE</code> at all (such as the <code>DELTA</code> line). This is because those lines happen to also have a <em>single</em> apostrophe (<code>'</code>) in their comments (i.e. <code>AREN'T</code>).</p>
  
  <p>I thought of piping the output to remove the lines I don't want with:</p>
  
  <pre><code># grep "\bANGLE\b" SRC_FILE.BAS | grep -v "'.*\bANGLE\b"
  </code></pre>
  
  <p>But unfortunately it also removes the lines of code I do want that just happen to have "<code>ANGLE</code>" in their comments.</p>
  
  <p>How do I get grep to match the lines of actual code involving <code>ANGLE</code> and ignore those lines with <em>only</em> matches in the comments?</p>