<script type="text/javascript">
<!--
function $(str){return document.getElementById(str);}
function show() {
  var str = $("strIn").value;
  str=str.replace(/\[B\]/,"<b>"); //替换为<b>
  str=str.replace(/\[\/B\]/,"</b>"); //替换为</b>
  $("cont").innerHTML = str;
}//-->
</script>
<textarea name="name" cols="50" rows="5" id="strIn"></textarea>
<br>
<input name="" type="button" onClick="show()" value="show">
<div id="cont"></div>

解决方案 »

  1.   

    把[FONT=宋体]替换成<font face="宋体">的正则我不会写!
      

  2.   

    <script>
    alert('[font=字体]字体[/font]'.replace(/\[font=(.+)\](.+)\[\/font\]/i,'<font face="$1">$2</font>'));
    </script>
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> neverUbbConverter Of never Modules - http://www.never-online.net </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="never-online, blueDestiny">
    <META NAME="Keywords" CONTENT="never-online, blueDestiny">
    <META NAME="Description" CONTENT="http://www.never-online.net">
    <STYLE>
    <!--
    body, pre, td
    {
    font-size: 0.8em; 
    font-family: verdana; 
    }
    h1
    {
    font-size: 1.8em; 
    }
    .copyright
    {
    text-align: center; 
    font-size: 0.8em; 
    font-weight: normal; 
    }
    textarea
    {
    width: 100%; 
    height: 200px; 
    }
    -->
    </STYLE>
    </HEAD>
    <h1 align="center">neverUbbConverter Of never Modules</h1>
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    //<![CDATA[
    /* ---------------------------------------------
    // never UBB namespace and config 
    ------------------------------------------------*/
    var App = new Object();
    App.neverUbbConverter =
    {
    _ubbuid : "ubbuid",
    _ubbValue : null, 
    getElById : document.getElementById || document.all, // ----------------------------------------ubb2Html : function(val)
    {
    val = val.replace(/\
    val = val.replace(/\[b\]([^\[\]]*)\[\/b\]/ig, "<b>$1</b>");
    val = val.replace(/\[strong\]([^\[\]]*)\[\/strong\]/ig, "<strong>$1</strong>");
    val = val.replace(/\[i\]([^\[\]]*)\[\/i\]/ig, "<i>$1</i>");
    val = val.replace(/\[a href=\ "?([^ \'\"\[\]]*)\"?\]([^\[\]]*)\[\/a\]/ig, "<a href=\"$1\" target=\"_blank\">$2</a>");
    return val; 
    }, 
    html2Ubb : function(val) 

    val = val.replace(/\ < *img (.+ )*src=["|']?([^ ="']*)["|']?( .+)*\/?\>/ig, ""); // img
    val = val.replace(/ <(\/?)b>/ig, "[$1b]"); // b
    val = val.replace(/ <(\/?)strong>/ig, "[$1strong]"); // strong
    val = val.replace(/ <(\/?)i>/ig, "[$1i]"); // i
    val = val.replace(/ <a (.+ )*href=\"?([^ \"\']*)\"?( .+)*>([^<>]*)< *\/a *>/ig, "[a href=\"$2\"]$4[/a]");// a
    return val; 
    }, 
    getElValue : function (val) 

    var u = this.getElById(val); 
    var a = u.tagName; 
    if (a== "INPUT" || a=="TEXTAREA") {return u.value;} else {return u.innerHTML};
    }, 
    setElValue : function (val1, val2) 

    var u = this.getElById(val1); 
    var a = u.tagName; 
    if (a== "INPUT" || a=="TEXTAREA") {u.value = val2;} else {u.innerHTML = val2};

    };
    /* ---------------------------------------------
    // never UBB converter API 
    ------------------------------------------------*/
    App.neverUbbConverter.convert = function (convertType)
    {
    var type = (convertType) ? convertType : 1; 
    var retval = "";
    var elValue = this.getElValue(this._ubbuid); 
    if (type == 1) { retval = App.neverUbbConverter.html2Ubb(elValue); } 
    else { retval = App.neverUbbConverter.ubb2Html(elValue); } 
    this._ubbValue = retval; 
    return retval; 
    };
    App.neverUbbConverter.output = function (uid)
    {
    this.setElValue(uid, this._ubbValue); 
    };
    App.neverUbbConverter.setUbbuid = function (uid)
    {
    this._ubbuid = uid; 
    };
    /* ---------------------------------------------
    // never UBB converter Demo 
    ------------------------------------------------*/
    function HandleHtml2Ubb()
    {
    App.neverUbbConverter.setUbbuid( "divUbbUid");
    App.neverUbbConverter.convert(1); // Html to ubb 
    App.neverUbbConverter.output( "divoutputUid");
    };
    function HandleUbb2Html()
    {
    App.neverUbbConverter.setUbbuid( "tx3");
    App.neverUbbConverter.convert(2); // ubb to Html 
    App.neverUbbConverter.output( "tx4");
    };
    // util.addEvent(window, 'load', HandleOnload);
    //]]>
    </SCRIPT>
    <BODY><TABLE>
    <TR>
    <TD width="50%"><textarea id="divUbbUid">
    <img src="123.gif"/>
    <strong>http://blog.csdn.net/BlueDestiny/</strong>
    <img src="im_BlueDestiny_never-online.jpg" border="0"/>
    <a href="http://blog.csdn.net/BlueDestiny/">blueDestiny</a>
    </textarea><textarea id="divoutputUid"></textarea>
    <hr>
    <input type="button" value="Html convert to ubb" onclick="HandleHtml2Ubb()"/></TD>
    <TD width="50%"><textarea id="tx3">
    [img]123.gif" alt="" />
    [strong]http://blog.csdn.net/BlueDestiny/[/strong][a href="http://blog.csdn.net/BlueDestiny/"]blueDestiny[/a]
    </textarea><textarea id="tx4"></textarea>
    <hr>
    <input type="button" value="Ubb convert to Html" onclick="HandleUbb2Html()"/></TD>
    </TR>
    </TABLE><h4 class="copyright">
    Power By BlueDestiny, never-online, 
    <a href="http://www.never-online.net">http://www.never-online.net</a> 
    </h4>
    </BODY>
    </HTML>