'本人做的一些小东西(仅供参考)
Function ReplaceTest(str,patrn, replStr)
  Dim regEx ' 建立变量。
  Set regEx = New RegExp ' 建立正则表达式。
  regEx.Pattern = patrn ' 设置模式。
  regEx.IgnoreCase = TRUE ' 设置是否区分大小写。
  regEx.Global = true '设置全程匹配。
  ReplaceTest = regEx.Replace(str,replStr) ' 作替换。
End Function
dim ubb(46,1)
ubb(0,0) = "\[img\](.*)\[\/img\]"
ubb(0,1) = "<a target=_blank href=$1 title=点击看原图><img src=$1 border=0></img></a>"
ubb(1,0) = "[^\=\>\]]((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@[\]\':+!]+)"
ubb(1,1) = "<a target=_blank href=$1>$1</a>"
ubb(2,0) = "\[(center|left|right)\]"
ubb(2,1) = "<div align=$1>"
ubb(3,0) = "\[\/(center|left|right)\]"
ubb(3,1) = "</div>"
ubb(4,0) = "\[size=([1-7])\]"
ubb(4,1) = "<font size=$1>"
ubb(5,0) = "\[\/size\]"
ubb(5,1) = "</font>"
ubb(6,0) = "\[color=([A-Za-z0-9\#]+)\]"
ubb(6,1) = "<font color=$1>"
ubb(7,0) = "\[\/color\]"
ubb(7,1) = "</font>"
ubb(8,0) = "\[(b)\]"
ubb(8,1) = "<$1>"
ubb(9,0) = "\[\/(b)\]"
ubb(9,1) = "</$1>"
ubb(10,0) = "\[(i)\]"
ubb(10,1) = "<$1>"
ubb(11,0) = "\[\/(i)\]"
ubb(11,1) = "</$1>"
ubb(12,0) = "\[(u)\]"
ubb(12,1) = "<$1>"
ubb(13,0) = "\[\/(u)\]"
ubb(13,1) = "</$1>"
ubb(14,0) = "\[(big)\]"
ubb(14,1) = "<$1>"
ubb(15,0) = "\[\/(big)\]"
ubb(15,1) = "</$1>"
ubb(16,0) = "\[(small)\]"
ubb(16,1) = "<$1>"
ubb(17,0) = "\[\/(small)\]"
ubb(17,1) = "</$1>"
ubb(18,0) = "\[(sub)\]"
ubb(18,1) = "<$1>"
ubb(19,0) = "\[\/(sub)\]"
ubb(19,1) = "</$1>"
ubb(20,0) = "\[(sup)\]"
ubb(20,1) = "<$1>"
ubb(21,0) = "\[\/(sup)\]"
ubb(21,1) = "</$1>"
ubb(22,0) = "\[(tt)\]"
ubb(22,1) = "<$1>"
ubb(23,0) = "\[\/(tt)\]"
ubb(23,1) = "</$1>"
ubb(24,0) = "\[face=([^\[]*)\]"
ubb(24,1) = "<font face=$1>"
ubb(25,0) = "\[\/face\]"
ubb(25,1) = "</font>"
ubb(26,0) = "\[url=([^\[]*)\]"
ubb(26,1) = "<a href=$1 target=_blank>"
ubb(27,0) = "\[url\](.*)\[\/url\]"
ubb(27,1) = "<a target=_blank href=$1>$1</a>"
ubb(28,0) = "\[email=(\S+\@.[^\[]*)\](.*)\[\/email\]"
ubb(28,1) = "<A HREF=""mailto:$1"" TARGET=_blank>$2</A>"
ubb(29,0) = "\[email\](\S+\@.[^\[]*)\[\/email\]"
ubb(29,1) = "<A HREF=""mailto:$1"" TARGET=_blank>$1</A>"
ubb(30,0) = "\[pm=\(([0-9\%]+)\,([0-9\%]+)\)\]([^\[]*)\[\/pm\]"
ubb(30,1) = "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 ><param name=ShowStatusBar value=-1><param name=Filename value=$3><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$3 width=$1 height=$2></embed></object>"
ubb(31,0) = "\[rm=\(([0-9\%]+)\,([0-9\%]+)\)\]([^\[]*)\[\/rm\]"
ubb(31,1) = "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2><PARAM NAME=SRC VALUE=$3><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1><PARAM NAME=SRC VALUE=$3><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>"
ubb(32,0) = "\n([^\&])"
ubb(32,1) = "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$1"
ubb(33,0) = "\n"
ubb(33,1) = "<br>"
ubb(34,0) = "&amp;"
ubb(34,1) = "&"
ubb(35,0) = "\[\/url\]"
ubb(35,1) = "</a>"
ubb(36,0) = "\[flash\](.*)\[\/flash\]"
ubb(36,1) = "<embed src=$1 width=411 quality=high name=flash allowScriptAccess=sameDomain type=application/x-shockwave-flash pluginspage=http://www.macromedia.com/go/getflashplayer>"
ubb(37,0) = "\[quote\]"
ubb(37,1) = "<div style='margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3'>"
ubb(38,0) = "\[\/quote\]"
ubb(38,1) = "</div>"
ubb(39,0) = "\[fly\]"
ubb(39,1) = "<marquee behavior=alternate>"
ubb(40,0) = "\[\/fly\]"
ubb(40,1) = "</marquee>"
ubb(41,0) = "\[move\]"
ubb(41,1) = "<marquee>"
ubb(42,0) = "\[\/move\]"
ubb(42,1) = "</marquee>"
ubb(43,0) = "\[glow=\(([0-9]+),([a-zA-Z0-9\#]+),([0-9]+)\)\]"
ubb(43,1) = "<div style='FILTER:glow(color=$2, strength=$3); WIDTH:$1px'>"
ubb(44,0) = "\[\/glow\]"
ubb(44,1) = "</div>"
ubb(45,0) = "\[shadow=\(([0-9]+),([a-zA-Z0-9\#]+),([0-9]+)\)\]"
ubb(45,1) = "<div style='FILTER:shadow(color=$2, strength=$3); WIDTH:$1px'>"
ubb(46,0) = "\[\/shadow\]"
ubb(46,1) = "</div>"
'转换文本的ubb标签
function replaceubb(str)
dim rstr
rstr = str
dim i
if myempty(rstr) then
for i = 0 to ubound(ubb,1)
rstr = replacetest(rstr,ubb(i,0),ubb(i,1))'替换所有的ubb标签
next
end if
replaceubb = rstr
end function

解决方案 »

  1.   

    JS支持UBB吗
    UBB是VBS内置的吗?
    我看到有些例子里面没有用到正则表达式就只是纯粹的替换那是怎么回事?另外:表单里面的数据不经过UBB转换
    直接存入数据库的话
    那里面的回车、换行、空格等格式信息能保留吗
      

  2.   

    都是自己写的
    那个语言也不内置
    ubb语法也是自己定义的
    当然ubb语法流行了整麽久 已经有了自己一套通用的语法数据都是可以保留的 包括那些回车、换行、空格等字符
      

  3.   

    这是JS的对特殊字符的转换.一直用到数据从<textarea></textarea>提交到数据库
    并保持格式.<script language=javascript>
    function HTMLEnCode(str)
    {
       var s = "";
       if (str.length == 0) return "";
       s = str.replace(/&/g, "&gt;");
       s = s.replace(/</g,   "&lt;");
       s = s.replace(/>/g,   "&gt;");
       s = s.replace(/ /g,   "&nbsp;");
       s = s.replace(/\'/g,  "&#39;");
       s = s.replace(/\"/g,  "&quot;");
       s = s.replace(/\n/g,  "<br>");
       return s;
    }
    function HTMLDeCode(str)
    {
       var s = "";
       if (str.length == 0) return "";
       s = str.replace(/&gt;/g, "&");
       s = s.replace(/&lt;/g,   "<");
       s = s.replace(/&gt;/g,   ">");
       s = s.replace(/&nbsp;/g,   " ");
       s = s.replace(/&#39;/g,  "\'");
       s = s.replace(/&quot;/g,  "\"");
       s = s.replace(/<br>/g,  "\n");
       return s;
    }
    </script>
    <textarea id="sText"></textarea>
    <input type="button" onclick="alert(HTMLEnCode(sText.value))" value="Format">
      

  4.   

    UBB,是自己实现的.这就是我用JavaScript为脚本写的实现UBB的ASP程序.demo.asp <% @Language="JavaScript" %>
    <%
    function baoUBB(str)
    {
        var reg = /(\[url\])(\S+)(\[\/url\])/g
        str = str.replace(reg,'<a href="$2" target="_blank">$2</a>')
        return str
    }
    function isEmpty(obj)
    {
        return !(String(obj)!="" && String(obj)!="undefined")
    }
    var content = Request.Form("content");
    if(!isEmpty(content))Response.Write(baoUBB(String(content)))
    %>
    <form name="form1" action="demo.asp" method="post">
    <textarea name="content" style="width:200;height:150">http://www.baidu.com</textarea>
    <input type=submit>
    </form>附:
    在ASP中利用“正则表达式” 对象实现UBB风格的论坛
    http://www0.ccidnet.com/tech/web/2000/04/17/58_598.html
      

  5.   

    JS自己写函数,上面已经列出一部分了,主要是理解正则表达式,按照一定的格式替换相应的内容。
    第二步,把自己要替换掉的内容用JS函数替换掉就完了。
      

  6.   

    UBB是自己写的函数。可以用vbs写也可以用js写。。呵。我只知道这么多。。
      

  7.   

    UBB是自己写的函数。可以用vbs写也可以用js写
    本人喜欢vbs,但是现在也习惯了js,感觉各有千秋。
    都有爽和不爽的一面。