title: Textmate Regex Find Replace Help
body: <p>I've got a project I'm working on converting some legacy perl cgi forms to PHP.  A lot of this requires finding / replacing information.  In one such case, I have lines like this in the perl script:</p>
  
  <pre><code>&lt;INPUT type="radio" name="trade" value="1" $checked{trade}-&gt;{1}&gt;
  </code></pre>
  
  <p>which needs to read:</p>
  
  <pre><code>&lt;INPUT type="radio" name="trade" value="1" &lt;?php echo checked('trade', 1); ?&gt;&gt;
  </code></pre>
  
  <p>Another example to show some variation in how these tags might show up in the perl/html:</p>
  
  <pre><code>&lt;INPUT type="radio" name="loantype" value="new" $checked{loantype}-&gt;{new}&gt;
  &lt;INPUT type="radio" name="loantype" value="new" $checked{'loantype'}-&gt;{new}&gt;
  &lt;INPUT type="radio" name="loantype" value="new" $checked{'loantype'}-&gt;{'new'}&gt;
  &lt;INPUT type="radio" name="loantype" value="new" $checked{loantype}-&gt;{'new'}&gt;
  </code></pre>
  
  <p>As you can see, the quotes can be about anywhere, but that's not my problem.  I decided to write a find / replace regex in textmate to make my life a bit easier.  My Regex looks like:</p>
  
  <pre><code>Find:     \$checked\{'?([^']+)'?\}-&gt;\{'?([^']+)'?\}
  Replace:  &lt;?php echo checked('$1', '$2'); ?&gt;
  </code></pre>
  
  <p>This worked fine in the first file I did it with, but for some reason in the current file the Regex has become really greedy, matching many lines.  it'll match the begininng (\$checked...) and then match up to the last time the character '}' appears.  I've tried a few variations to make it a bit less greedy including:</p>
  
  <pre><code> ^(.*)\$checked\{'?([^']+)'?\}-&gt;\{'?([^']+)'?\}(.*)$
  </code></pre>
  
  <p>But even that seems to match multiple lines.  I assumed the ^ at the beginning would only match the beginning of a line, and the $ at the end would only match the end... constraining my match to 1 line... but it doesn't it seems.  </p>
  
  <p>/me fails at regex</p>
  
  <p>Thanks for any help,
  Mike</p>