title: Processing Javascript RegEx submatches
body: <p>I am trying to write some JavaScript RegEx to replace user inputed tags with real html tags, so <code>[b]</code> will become <code>&lt;b&gt;</code> and so forth. the RegEx I am using looks like so</p>
  
  <pre><code>var exptags = /\[(b|u|i|s|center|code){1}]((.){1,}?)\[\/(\1){1}]/ig;
  </code></pre>
  
  <p>with the following JavaScript</p>
  
  <pre><code>s.replace(exptags,"&lt;$1&gt;$2&lt;/$1&gt;");
  </code></pre>
  
  <p>this works fine for single nested tags, for example:</p>
  
  <pre><code>[b]hello[/b] [u]world[/u]
  </code></pre>
  
  <p>but if the tags are nested inside each other it will only match the outer tags, for example </p>
  
  <pre><code>[b]foo [u]to the[/u] bar[/b]
  </code></pre>
  
  <p>this will only match the <code>b</code> tags. how can I fix this? should i just loop until the starting string is the same as the outcome? I have a feeling that the <code>((.){1,}?)</code> patten is wrong also?</p>
  
  <p>Thanks</p>