Forum Moderators: open
===========================================
var message=document.getElementById('message').value;
var bbcode = new Array("(b)","(/b)");
var htmlcode = new Array("<b>","</b>");
for(var i = 0 ; i < bbcode.length ; i ++ )
{
message=message.replace(bbcode[i],htmlcode[i]);
}
var bbcode = [/\(b\)/gi, /\(\/b\)/gi];
The first pattern: /\(b\)/gi
That says match the literal '(' followed by a 'b' followed by a literal ')', and the 'g' attribute makes it 'Global' (matches all instances). The 'i' attribute will make it case-insensitive, so you could do:
(b)bold(/b) (B)bold(/B) (b)bold(/B)
and you'd end up with:
<b>bold</b> <b>bold</b> <b>bold</b>
The second pattern: /\(\/b\)/gi
That says match the literal '(' followed by the literal '/' followed by 'b' followed by the literal ')'. Again, the 'g' makes it global and the 'i' makes it case insensitive.