title: Regex to replace Boolean with bool
body: <p>I am working on a C++ code base that was recently moved from X/Motif to Qt.  I am trying to write a Perl script that will replace all occurrences of Boolean (from X) with bool.  The script just does a simple replacement.  </p>
  
  <pre><code>s/\bBoolean\b/bool/g
  </code></pre>
  
  <p>There are a few conditions.   </p>
  
  <p>1) We have CORBA in our code and \b matches CORBA::Boolean which should <strong>not</strong> be changed.<br>
  2) It should not match if it was found as a string (i.e. "Boolean")</p>
  
  <p><strong>Updated:</strong></p>
  
  <p>For #1, I used lookbehind</p>
  
  <pre><code>s/(?&lt;!:)\bBoolean\b/bool/g;
  </code></pre>
  
  <p>For #2, I used lookahead.</p>
  
  <pre><code>s/(?&lt;!:)\bBoolean\b(?!")/bool/g&lt;/pre&gt;
  </code></pre>
  
  <p>This will most likely work for my situation but how about the following improvements?</p>
  
  <p>3) Do not match if in the middle of a string (thanks <a href="https://stackoverflow.com/users/3101/nohat">nohat</a>).<br>
  4) Do not match if in a comment.  (// or /**/) </p>