title: How to search a file for a pattern and conditionally replace it?
body: <p>I've got some old PHP files that I'm trying to update to work with v7.  There are a bunch of places where the author used short open tags (ie, <code>&lt;?</code>) and I need to change them to the normal open tags (<code>&lt;?php</code>).  But he also sometimes used the normal open tag as well as the short echo tag (<code>&lt;?=</code>).  So those two instances should NOT be updated.  And a single line in a file can contain more than one open tag that needs to be updated and/or should not be updated.</p>
  
  <p>So to summarize, I need to search a file for <code>&lt;?</code> and replace it with <code>&lt;?php</code> ONLY IF it does not have either an equal sign or 'php' after it.</p>
  
  <p>Some examples:</p>
  
  <p>This line has two instances of <code>&lt;?</code> that need to be replaced by <code>&lt;?php</code>:</p>
  
  <pre><code>&lt;input type="radio" name="Period" value="Month" &lt;? if (($Period=="Month") || !isset($Period)){ ?&gt;checked="checked" &lt;? } ?&gt;&gt;
  </code></pre>
  
  <p><br>
  This line has several instances of <code>&lt;?=</code>, none of which should be replaced (ie, this line would be left as-is):</p>
  
  <pre><code>&lt;FORM METHOD=POST ACTION="&lt;?=$PHP_SELF?&gt;?s=&lt;?=$s?&gt;&amp;t=&lt;?=$t?&gt;&amp;order=&lt;?=$order?&gt;&amp;sens=&lt;?=$sens?&gt;&amp;current_page=&lt;?=$current_page?&gt;"&gt;
  </code></pre>
  
  <p><br>
  This line has several instances of <code>&lt;?=</code> which should be left as-is and one instance of <code>&lt;?</code> which should be replaced by <code>&lt;?php</code>:</p>
  
  <pre><code>&lt;a href="&lt;?=$PHP_SELF?&gt;?s=1&amp;t=&lt;?=$t?&gt;&amp;order=&lt;?=$order?&gt;&amp;sens=&lt;?=$sens?&gt;&amp;current_page=&lt;? echo ($current_page+1)?&gt;
  </code></pre>
  
  <p><br>
  I could crawl through the file and get the position of every <code>&lt;?</code> and then see what the next few characters are but it seems like there would be a better way.  Is there a regex way to do what I need?</p>