<?php
$string = 'antes[caption id="blabla"](aqui aparece a imagem)[/caption]depois[b]xx[/b]' ;
echo "Teste1\n " ;
echo "\n \n Teste2\n " ;
echo "\n \n Teste3\n " ;
echo preg_replace ( '/(.*)\[caption.*\](.*)\[\/caption\](.*)/' , '$1 { $2 } $3' , $string ) ;
echo "\n \n Teste4\n " ;
echo preg_replace ( '/.*\[caption.*\](.*)\[\/caption\].*/' , '$1' , $string ) ;
PD9waHAKCgkkc3RyaW5nID0gJ2FudGVzW2NhcHRpb24gaWQ9ImJsYWJsYSJdKGFxdWkgYXBhcmVjZSBhIGltYWdlbSlbL2NhcHRpb25dZGVwb2lzW2JdeHhbL2JdJzsKCiAgICBlY2hvICJUZXN0ZTFcbiI7CgllY2hvIHByZWdfcmVwbGFjZSgnL1xbXC8/Y2FwdGlvbi4qXF0vVScsICcnLCAkc3RyaW5nICk7CgogICAgZWNobyAiXG5cblRlc3RlMlxuIjsKCWVjaG8gcHJlZ19yZXBsYWNlKCcvXFsuKlxdL1UnLCAnICcsICRzdHJpbmcgKTsKCiAgICBlY2hvICJcblxuVGVzdGUzXG4iOwogICAgZWNobyBwcmVnX3JlcGxhY2UoICcvKC4qKVxbY2FwdGlvbi4qXF0oLiopXFtcL2NhcHRpb25cXSguKikvJywgJyQxIHsgJDIgfSAkMycsICRzdHJpbmcgKTsKICAgIAogICAgZWNobyAiXG5cblRlc3RlNFxuIjsKICAgIGVjaG8gcHJlZ19yZXBsYWNlKCAnLy4qXFtjYXB0aW9uLipcXSguKilcW1wvY2FwdGlvblxdLiovJywgJyQxJywgJHN0cmluZyApOwo=