string.replace('[b]','<b>')
s="[b]foo[/b]foo[s]foo[/s]" re=/(\[)|(\])/g alert(s.replace(re, function(a, b, c){if(a===b) return "<"; if(a===c) return">"})) // <b>foo</b>foo<s>foo</s>
s="[script]xss()[/script]foo[s]foo[/s]" re=/(\[)|(\])/g alert(s.replace(re, function(a, b, c){if(a===b) return "<"; if(a===c) return">"}))