Unique value in find and replace
<p>My problem is that im using jQuery to replace the bb tags in a message. I want to replace all the <code>[youtube][/youtube]</code> with a youtube video and so far it works only if there is only 1 <code>[youtube][/youtube]</code> tag. If there is multiple <code>[youtube][/youtube]</code> tags in a message they change all of them to the same video.</p>

<p>This is the code:</p>

<pre><code>&lt;script&gt;
    function playt(a,b){
        //nothing yet
    }

    f=0;
    function ytbb(s,w){
        f++;
        results = s.match("[\\?&amp;]v=([^&amp;#]*)");
        vid = ( results === null ) ? s : results[1];
        $('.yt'+w).html('&lt;div onclick="playt('+f+',\''+vid+'\')" class="playt"&gt;&lt;/div&gt;&lt;img width="200" height="151" src="http://img.youtube.com/vi/'+vid+'/0.jpg"&gt;');
    }

    function ubbcode(txt) {
        var find    = [
            /\[youtube\](.*?)\[\/youtube\]/gi,
            /(?:%lb%){3,}/g
        ];
        var e =   Math.floor(Math.random()*99999999999);
        var replace = [
            '&lt;script&gt;ytbb("$1","'+e+'")&lt;/script&gt; &lt;div class="rmg yt'+e+'"&gt;&lt;/div&gt;',
            '%lb%%lb%'
        ];

        for(var i in find) {
            txt = txt.replace(find[i],replace[i]);
        }
        txt = txt.replace(/%lb%/g,'&lt;br /&gt;');
        return txt;
    }
&lt;/script&gt;
</code></pre>

<p>Can anybody help me with this?</p>
