title: use php, grep and regex to search and replace lines of code in file
body: <p>I have a php file that can read the contents of other files perfectly and return them as a string.</p>
  
  <pre><code>$contents = $file-&gt;read(); // return as string.
  </code></pre>
  
  <p>i need to be able to search and replace certain lines</p>
  
  <p>lines that begin with <code>$this-&gt;Session-&gt;setFlash</code> and end with <code>, true));</code> must be replaced with </p>
  
  <p>lines that begin with 
  <code>$this-&gt;Session-&gt;setFlash</code> and end with <code>, true), 'default', array('class'=&gt;'flash_failure'));</code></p>
  
  <p>I have grep in my machine, if that helps.</p>
  
  <p>finally after the contents is changed, i have a function that will write the contents back</p>
  
  <pre><code>$file-&gt;write($contents);
  </code></pre>
  
  <p>I know this helps to find the lines, but I have no idea how to replace.</p>
  
  <pre><code>^.*Session-&gt;setFlash.*, true\)\);$
  </code></pre>