I have a regex that should rewrite [img]foo.bar[/img]
to <img src=foo.bar>
and in fact, it does. The problem comes in when I have two or more of those [img]url.ext[/img]
in the string. Instead of matching each one separately, it matches the first [img]
and the last [/img]
and leaves the urls and tags in the middle as part of the src
. My php code is $newstring = preg_replace('%\[img\](.+)\[/img\]%', '<img src=${1}>', $string);
a working example is https://www.regex101.com/r/mJ9sM0/1