最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
正则表达式在网络编程中的运用(5)
时间:2022-06-30 10:55:26 编辑:袖梨 来源:一聚教程网
三、UBB正则表达模板实例
下面是我写的一个UBB函数,这个函数基本上能使你的论坛成为一个优秀的UBB代码论坛了。当然,通过改进后,你可以得到一个更强大的UBB论坛。
Function ReThestr(face,str)
dim re,str
re=">"
str=checkexp(re,str,">")
re="<"
str=checkexp(re,str,"<")
re=" /"
str=checkexp(re,str,"<P>")
re=chr(32)
str=checkexp(re,str," ")
re=""
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 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]" '替换字体大小
下面是我写的一个UBB函数,这个函数基本上能使你的论坛成为一个优秀的UBB代码论坛了。当然,通过改进后,你可以得到一个更强大的UBB论坛。
Function ReThestr(face,str)
dim re,str
re=">"
str=checkexp(re,str,">")
re="<"
str=checkexp(re,str,"<")
re=" /"
str=checkexp(re,str,"<P>")
re=chr(32)
str=checkexp(re,str," ")
re=""
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 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]" '替换字体大小