title: javascript replace() multiple bbcode instances with multiple html
body: <p>I need to get the javascript replace() function to replace every instance of a [b] or [/b] with <code>&lt;b&gt;</code> or <code>&lt;/b&gt;</code>. I tried this with the global tag but it doesn't work and comes out oddly:</p>
  
  <pre><code>document.write(str.replace(/[b]/g,'&lt;b&gt;').replace(/[/b]/g,'&lt;/b&gt;'));
  </code></pre>
  
  <p>results in the output being:</p>
  
  <pre><code>[&lt;&gt;]&lt;&gt;la&lt;&gt;la[&lt;&gt;][&lt;&gt;]&lt;&gt;la&lt;&gt;la[&lt;&gt;] 
  </code></pre>
  
  <p>I also tried changing the first part to:</p>
  
  <pre><code>  document.write(str.replace(/[[b]]/g,'&lt;b&gt;').replace(/[[/b]]/g,'&lt;/b&gt;'));
  </code></pre>
  
  <p>which kind of works, but there's odd ]s everywhere... like so:</p>
  
  <pre><code>[blabla[/[blabla[/
  </code></pre>
  
  <p>I know there's probably something obvious I'm missing here... But I can't find it... any help and I will love you forever XD</p>