日期:2012-01-15  浏览次数:20847 次

  三、UBB正则表达模板实例

  下面是我写的一个UBB函数,这个函数基本上能使你的论坛成为一个优秀的UBB代码论坛了。当然,通过改进后,你可以得到一个更强大的UBB论坛。

Function ReThestr(face,str)
 dim re,str

 re="\>"
 str=checkexp(re,str,">")

 re="\<"
 str=checkexp(re,str,"<")

 re="\n\r\n/"
 str=checkexp(re,str,"<P>")

 re=chr(32)
 str=checkexp(re,str," ")

 re="\r"
 str=checkexp(re,str," ")

 re="\[img\]((http:(\/\/|\\\\)){1}((\w)+[.]){1,3}_
(net|com|cn|org|cc|tv)(((\/[\~]*|\\[\~]*)
(\w)+)|[.](\w)+)*(\w)+[.]{1}(gif|jpg|png))\[\/img\]" '查找图片地址
 str=checkexp(re,str," <img src='$1'> ")

 re="\[w\](http:(\/\/|\\\\)((\w)+[.]){1,}_
(net|com|cn|org|cc|tv)(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*
(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)\[\/w\]" '查找帧地址
 str=checkexp(re,str,"<iframe width='300' height='300' src='$1'></iframe>")

 re="([^('>)])(<br>)*((http|https|ftp):_
(\/\/|\\\\)((\w)+[.]){1,}(net|com|cn|org|cc|tv|_
([0-9]{1,3}))(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*_
(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)" '查找链接地址
 str=checkexp(re,str,"$1$2 <a href='$3' target=_blank>$3</a> ")
 re="([^(http://|http:\\)])((www|cn)[.](\w)+[.]{1,}_
(net|com|cn|org|cc)(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*
(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)
" '查找不以http://开头的地址
 str=checkexp(re,str,"$1 <a href='http://$2' target=_blank>$2</a> ")
 re="([^(=)])((\w)+[@]{1}((\w)+[.]){1,3}(\w)+)" '查找邮件地址
 str=checkexp(re,str," <a href='mailto:$2'>$2</a> ")
 re="\[color=(((\w)+)|][#][0-F]{6})\]((.)+)\[\/color\]" '替换字体色彩
 str=checkexp(re,str,"<font color='$1'>$4</font>")
 re="\[size=(][0-9]{1})\]((.)+)\[\/size\]" '替换字体大小
 str=checkexp(re,str,"<font size='$1'>$2</font>")
 re="\[font=((.)+){1,3}\]((.)+)\[\/font\]" '替换字体
 str=checkexp(re,str,"<font face='$1'>$3</font>")
 re="(\[b\])(.+)(\[\/b\])" '加粗字体
 str=checkexp(re,str,"<b>$2</b>")
 re="(\[u\])(.+)(\[\/u\])" '下画线
 str=checkexp(re,str,"<u>$2</u>")
 re="(\[li\])(.+)(\[\/li\])" '列表
 str=checkexp(re,str,"<li>$2</li>")
 re="(\[QUOTE\])(.+)(\[\/QUOTE\])" '引用
 str=checkexp(re,str,"_
<BLOCKQUOTE>引用:<HR SIZE=1>$2<HR SIZE=1></BLOCKQUOTE>")
 re="\[email=((\w)+][@]{1}((\w)+[.]){1,3}(\w)+)\](.+)(\[\/email\])" '邮件
 str=checkexp(re,str,"<a href=mailto:$1>$6</a>")
 re="(\[center\])(.+)(\[\/center\])" '居中
 str=checkexp(re,str,"<center>$2</center>")

 re="fuck"
 str=checkexp(re,str,"***")

 re="操"
 str=checkexp(re,str,"***")

 re="sex"
 str=checkexp(re,str,"***")

 re="TMD"
 str=checkexp(re,str,"***")

 re="shit"
 str=checkexp(re,str,"***")

 ReThestr=str
end function


  UBB代码如下:

  • [font=impact] [/font]

      测试代码如下:


    http://cn.yahoo.com
    http://aol.com http://192.168.0.1
    www.yahoo.com how are you[/b]
    http://page2000.xiloo.com/~page2000?PageNo=2&action=del
    lucaihui@cmmail.com 大家好http:\\page2000.sh