Textmate Regex Find Replacement Help

I have a project that I am working on converting some legacy perl cgi forms to PHP. This requires searching / replacing information. In one such case, I have lines like this in a perl script:

<INPUT type="radio" name="trade" value="1" $checked{trade}->{1}>

      

which must be read:

<INPUT type="radio" name="trade" value="1" <?php echo checked('trade', 1); ?>>

      

Another example to show some changes in how these tags can be displayed in perl / html:

<INPUT type="radio" name="loantype" value="new" $checked{loantype}->{new}>
<INPUT type="radio" name="loantype" value="new" $checked{'loantype'}->{new}>
<INPUT type="radio" name="loantype" value="new" $checked{'loantype'}->{'new'}>
<INPUT type="radio" name="loantype" value="new" $checked{loantype}->{'new'}>

      

As you can see, quotes can be anywhere, but that's not my problem. I decided to write a find / replace regex in textmate to make my life a little easier. The regex looks like this:

Find:     \$checked\{'?([^']+)'?\}->\{'?([^']+)'?\}
Replace:  <?php echo checked('$1', '$2'); ?>

      

This worked fine in the first file I did it with, but for some reason in the current file, Regex got really greedy, matching many lines. it will match begininng (\ $ checked ...) and then match the last occurrence of the '}' character. I've tried several options to make it less greedy, including:

 ^(.*)\$checked\{'?([^']+)'?\}->\{'?([^']+)'?\}(.*)$

      

But even that looks like a few lines. I assumed that the ^ at the beginning would match the beginning of the line, and the $ at the end would only match the end ... limiting my match to 1 line ... but that doesn't seem to.

/ me doesn't work in regex

Thanks for any help, Mike

+1


source to share


1 answer


Try the following:

^(.*?)\$checked\{'?([^']+?)'?\}->\{'?([^']+?)'?\}(.*?)$

      



?

after *

and +

make them "inanimate".

+2


source







All Articles