Something like this:
<?php
$rgx = '/\[img\](https?:\/\/.+?\.(?:png|gif|jpg))\[\/img\]/';
$arr = array(
'sdvsvsdvsdv[img]http://www.website/folders/url_here.png[/img]sdvsdvsvdsvdsdv',
'sdvsvdsvd[img]https://www.website/folders/url_here.jpg[/img]svsnvlkn',
'sdvsdvsdv[img]https://www.website/folders/url_here.gif[/img]svdsvd'
);
$all = 'sdvsvsdvsdv[img]http://www.website/folders/url_here.png[/img]sdvsdvsvdsvdsdv
sdvsvdsvd[img]https://www.website/folders/url_here.jpg[/img]svsnvlknsdvsdvsdv[img]https://www.website/folders/url_here.gif[/img]svdsvd';
echo "Individual strings:
";
foreach ($arr as $str) {
echo preg_replace($rgx, '<img src="$1" alt="">', $str) . "
";
}
echo "
All together:
";
echo preg_replace($rgx, '<img src="$1" alt="">', $all) . "
";
Codepad:
http://codepad.org/n00B6akn
Some little tweaks:
Alternatively this tweak speeds up the regex I made by keeping it greedy instead of making the middle non-greedy:
$rgx = '/\[img\](https?:\/\/[^\[]*\.(?:png|gif|jpg))\[\/img\]/'
And here without as many slashes:
$rgx = '~\[img\](https?://[^\[]*\.(?:png|gif|jpg))\[/img\]~'
It makes sure the img tags are matched, and that whatever is inbetween them starts with http(s):// and ends with .png / .gif / .jpg. If you need better validation then something like what hwnd made initially (v1 of his answer) is more fitting (given you tweak his solution to your needs).