当前位置: 移动技术网 > IT编程>开发语言>.net > 一个新版本的ubb转化程序

一个新版本的ubb转化程序

2018年10月15日  | 移动技术网IT编程  | 我要评论
这段代码将用户输入的ubb代码转化为html格式,注意,需要script engine 5.0的支持(使用了regexp对象)

注:pattern中使用()将知道regexp记忆搜索到的值,$1是第一个(),其余类推。但$2的语法并不被5.0版本的vbscript.dll所支持,我检查了自己机器上的版本(安装过ie 5.5),发现vbscript.dll的版本为5.50.4629,最后修改日期为12月25日。该版本支持$1之类的语法,这个简单的改进使regexp的功能逐渐与perl的正则表达式靠近

function ubbcode(strcontent)

    dim objregexp
    set objregexp=new regexp
    objregexp.ignorecase =true
    objregexp.global=true
    url
    objregexp.pattern="([url])(https://s+?)([/url])"
    strcontent= objregexp.replace(strcontent,"<a href=""$2""
target=_blank>$2</a>")
    objregexp.pattern="([url])(s+?)([/url])"
    strcontent= objregexp.replace(strcontent,"<a href=""https://$2""
target=_blank>$2</a>")
    email
    objregexp.pattern="([email])(s+@s+?)([/email])"
    strcontent= objregexp.replace(strcontent,"<a
href=""mailto:$2"">$2</a>")

    objregexp.pattern="([img])(s+?)([/img])"
    strcontent=objregexp.replace(strcontent,"<img src=""$2"">")

    objregexp.pattern="([quote])(.+?)([/quote])"
    strcontent=objregexp.replace(strcontent,"<blockquote><font size=1
face=""verdana, arial"">quote:</font><hr>$2<hr></blockquote>")

    objregexp.pattern="([i])(.+?)([/i])"
    strcontent=objregexp.replace(strcontent,"<i>$2</i>")

    objregexp.pattern="([b])(.+?)([/b])"
    strcontent=objregexp.replace(strcontent,"<b>$2</b>")
    set objregexp=nothing
    ubbcode=strcontent
end function
=-=====================
sub ubbcode {
my $thepost = shift;
$thepost =~ s/([url])(https://s+?)([/url])/ <a href="$2"
target=_blank>$2</a> /isg;
$thepost =~ s/([url])(s+?)([/url])/ <a href="https://$2"
target=_blank>$2</a> /isg;
$thepost =~ s/([email])(s+@s+?)([/email])/ <a
href="mailto:$2">$2</a> /isg;
if (($ubbimages eq "on") && ($overrideimages ne "yes")) {
$thepost =~ s/([img])(s+?)([/img])/ <img src="$2"> /isg;
}

$thepost =~ s/([quote])(.+?)([/quote])/ <blockquote><font size="1"
face="verdana, arial">quote:</font><hr>$2<hr></blockquote>/isg;
$thepost =~ s/([i])(.+?)([/i])/<i>$2</i>/isg;
$thepost =~ s/([b])(.+?)([/b])/<b>$2</b>/isg;
return ($thepost);
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网