抓取所有以php字符开始和结束的字符串


Grab all string start and end with character php

我有这个字符串

"%John%" abxcca - "%Cameron%" , "%Warner%-%Bros%" 

我想提取包含%字符的单词列表预期结果为:[ 'John','Cameron','Warner','Bros']

如何在PHP中完成正则表达式?

我试过('%.*'%)+

但它只能从1 %到最后一个%,它不能分离

我做了一些正则表达式学习现在,这似乎工作…

$matches = [];
preg_match_all('/%(.*)%/U', '"%John%" abxcca - "%Cameron%" , "%Warner%-%Bros%"', $matches);

array (
  0 => 
  array (
    0 => '%John%',
    1 => '%Cameron%',
    2 => '%Warner%',
    3 => '%Bros%',
  ),
  1 => 
  array (
    0 => 'John',
    1 => 'Cameron',
    2 => 'Warner',
    3 => 'Bros',
  ),
)

IDK如果这是最好的方法,regex新手我自己。

我得到它 :).....................

%(.*?)%