title: BB-Code-RegEx in javascript
body: <p>I have this piece of code:</p>
  
  <pre><code>var s_1 = 'blabla [size=42]the answer[/size] bla bla blupblub';
  var s_2 = 'blabla [size=42]the answer[/size] bla bla blupblub [size=32] 32 [/size]';
  
  alert('Test-String:\n' + s_1 + '\n\nReplaced:\n' + size(s_1));
  alert('Test-String:\n' + s_2 + '\n\nReplaced:\n' + size(s_2));
  
  
  function size(s) {
      var reg = /\[size=(\d{1,2})\]([\u0000-\uFFFF]+)\[\/size\]/gi;
      s = s.replace(reg, function(match, p1, p2) {
          return '&lt;span style="font-size: ' + ((parseInt(p1) &gt; 48) ? '48' : p1) + 'px;"&gt;' + p2 + '&lt;/span&gt;';
      })
      return s;    
  }
  </code></pre>
  
  <p>It's supposed to replace all occurrences of the "[size=nn][/size]"-Tags but it only replaces the outer ones. I can't figure out how to replace all of them. (Please don't recommend to use a PHP-Script, I'd like to have a live-preview for the BB-Code formated Text)</p>
  
  <p><a href="http://jsfiddle.net/wdqLE/9/" rel="nofollow">Test it</a></p>