Php 使用正则表达式获取所有属性

Php 使用正则表达式获取所有属性,php,regex,Php,Regex,我的输入字符串是 $center="[{video('whats-new/reaction-vid1.jpg')} width=\"580\" height=\"326\" alt=\"\" video=\"Zb36h4K2IKQ\"]"; $pattern="/\[{video\('([a-zA-Z0-9\/\-\_]+)'\)}\s+(width|height|alt|video)=\"[^\"]+\"\]/"; if(preg_match($pattern,$center,$matches

我的输入字符串是

$center="[{video('whats-new/reaction-vid1.jpg')} width=\"580\" height=\"326\" alt=\"\" video=\"Zb36h4K2IKQ\"]";
$pattern="/\[{video\('([a-zA-Z0-9\/\-\_]+)'\)}\s+(width|height|alt|video)=\"[^\"]+\"\]/";
if(preg_match($pattern,$center,$matches)){
   print_r($matches);exit;
}
但是它不起作用。基本上我想增加宽度、高度、alt和视频的属性。我已经试了半个小时了。有人能给我指出正确的方向吗?

使用而不是


你是指两个额外的属性吗?对不起,~video在这里的含义是什么,因为$center是一个可变句子,它可能有valeus,例如“abcded[{video('whats-new/reaction-vid1.jpg')width=\'580\'height=\'326\'alt=\'video=\'Zb36h4K2IKQ\'gef”regex模式必须包含在分隔符中。我在
~
中包含了上面的正则表达式模式,我尝试过,似乎你的解决方案也能够处理“abcded[{video('whats-new/reaction-vid1.jpg')width=\'580\'height=\'326\'alt=\'video=\'Zb36h4K2IKQ\'gef”案例,谢谢,实际上我还有一个问题。在这种情况下,在获得所有preg_match_all值后,我想将输入字符串替换为“”,这样我可以将值重新格式化为html结构,例如,在真实内容中出现了很多输入字符串,是否有回调函数来执行此操作最初我使用的if(preg_match_all($pattern,$center,$matches)){$input=preg_replace($pattern,“,$input);}但似乎不起作用
<?php
$center="[{video('whats-new/reaction-vid1.jpg')} width=\"580\" height=\"326\" alt=\"\" video=\"Zb36h4K2IKQ\"]";
$pattern="~video\('\K[^']*|(?:width|height|alt|video)=\"\K[^\"]*~";
preg_match_all($pattern, $center, $matches);
print_r($matches);
?>
Array
(
    [0] => Array
        (
            [0] => whats-new/reaction-vid1.jpg
            [1] => 580
            [2] => 326
            [3] => 
            [4] => Zb36h4K2IKQ
        )

)