これはどう:
\[element title=(.*)picture=(\d+)\](.*?)(\[caption\](.*)\[/caption\])?\[/element\]
次の両方に一致します。
[element title=element title picture=32]Lorem ipsum dolor[caption]Photo by John Doe[/caption][/element]
[element title=element title picture=32]Lorem ipsum dolor[/element]
例
PHP では、次のように使用できます。
$regex = '#\[element title=(.*)picture=(\d+)\](.*?)(\[caption\](.*)\[/caption\])?\[/element\]#i';
$text = '[element title=element title picture=32]Lorem ipsum dolor[caption]Photo by John Doe[/caption][/element]';
preg_match ( $regex, $text, $match );
print_r( $match );
配列$matchにはいくつかの要素があります。(これらは、丸括弧と)正規表現で囲まれた文字列です。そのうちの 1 つがキャプション テキストです。
プログラムの実行と出力は、ここで確認できます http://ideone.com/vQ1T0。