<?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 );
?>