用于搜索和替换具有变量索引的字符串的正则表达式
Regex to search and replace a string with variable index
我需要帮助来制作一个正则表达式来查找像这样的字符串:
<?php if ($course['image']) { ?>
或
<?php if ($course['date']) { ?>
并替换为
{{$course->image}} or {{$course->date}} or {{$course->whateverindex}}
谢谢!
<\?php echo $(\w+)\['(\w+)']; \?>
替换为
{{$->}}
您可以通过以下方式找到您的台词:
<\?php if \($course\[[^]]+]\) \{ \?>
并替换为{{$course->image}}
如果您只需要指定 'image'
而不是匹配所有这些,您可以将 [^]]+
替换为 'image'
,例如:
<\?php if \($course\['image']\) \{ \?>
我需要帮助来制作一个正则表达式来查找像这样的字符串:
<?php if ($course['image']) { ?>
或
<?php if ($course['date']) { ?>
并替换为
{{$course->image}} or {{$course->date}} or {{$course->whateverindex}}
谢谢!
<\?php echo $(\w+)\['(\w+)']; \?>
替换为
{{$->}}
您可以通过以下方式找到您的台词:
<\?php if \($course\[[^]]+]\) \{ \?>
并替换为{{$course->image}}
如果您只需要指定 'image'
而不是匹配所有这些,您可以将 [^]]+
替换为 'image'
,例如:
<\?php if \($course\['image']\) \{ \?>