Search code examples
regexphpstorm

Regex to search and replace a string with variable index


I need help to make a regex to find string like:

<?php if ($course['image']) { ?>

or

<?php if ($course['date']) { ?>

and replace with

{{$course->image}} or {{$course->date}} or {{$course->whateverindex}}

thanks!


Solution

  • <\?php echo \$(\w+)\['(\w+)']; \?> 
    

    replace with

    {{\$$1->$2}}