我有一个 PHP 变量 (
$content
),我需要在其中找到如下所示的特定模式:
[gallery::name/of/the/folder/]
我要搜索:
- starting with literal characters `[gallery::`
- any other character (variable length)
- ending with "]"
到目前为止,在 PHP 中我有:
preg_match('/\[gallery\:/', $content, $matches, PREG_OFFSET_CAPTURE);
我可以找到
[gallery:
,但仅此而已。
我希望能够找到其余的(
:name/of/the/folder/]
)。
尝试捕捉它:
preg_match("/\[gallery::(.*?)]/", $content, $m);
现在
$m
是一个数组:
0 => [gallery::/name/of/the/folder/]
1 => /name/of/the/folder/
将正则表达式更改为
'/\[gallery::([A-Za-z\/]+)\]/'
由于我将文件夹/路径部分放在括号中,因此您应该从中获得一个捕获组。