开发者

preg_replace with curly brackets

开发者 https://www.devze.com 2023-01-04 06:20 出处:网络
I\'d like to replace the string \"{{edit(3)}}\" with \"open3close\" using pre开发者_运维百科g_replaceEscape { and } to \\{ and \\} in regex stringI\'m sorry if you wasted your time, i found a valid so

I'd like to replace the string "{{edit(3)}}" with "open3close" using pre开发者_运维百科g_replace


Escape { and } to \{ and \} in regex string


I'm sorry if you wasted your time, i found a valid solution.

preg_replace("/{{edit\((.*)\)}}/e","'open'.'\\\1'.'close'", $string);

input : {{edit(3)}}
output: open3close

0

精彩评论

暂无评论...
验证码 换一张
取 消