Match and parse the content of a square-braced placeholder in text

php, preg-match, regex, tags, text-parsing

Solution

Try capturing it:

preg_match("/\[gallery::(.*?)]/", $content, $m);

Now `$m` is an array:

0 => [gallery::/name/of/the/folder/]
1 => /name/of/the/folder/

Problem

I have a PHP variable (`$content`) where I need to find a certain pattern that looks like this: ``` [gallery::name/of/the/folder/] ``` I would like to search: ``` - starting with literal characters `[gallery::` - any other character (variable length) - ending with "]" ``` So far, in PHP I have: ``` preg_match('/\[gallery\:/', $content, $matches, PREG_OFFSET_CAPTURE); ``` I can find `[gallery:` but that's it. I would like to be able to find the rest (`:name/of/the/folder/]`).

Original source