pjblog的ubbcodeasp文件_正则表达式教程-查字典教程网
pjblog的ubbcodeasp文件
pjblog的ubbcodeasp文件
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:

复制代码 代码如下:

<%

'===========PBlog2 UBB代码转换代码==========

' Author:PuterJam

' Copryright PBlog2

' Update: 2005-12-29

'===========================================

Function UBBCode(ByVal strContent,DisSM,DisUBB,DisIMG,AutoURL,AutoKEY)

If isEmpty(strContent) Or isNull(strContent) Then

Exit Function

Else

Dim re, strMatchs, strMatch, rndID,tmpStr1,tmpStr2,tmpStr3,tmpStr4

Set re=new RegExp

re.IgnoreCase =True

re.Global=True

IF AutoURL=1 Then

re.Pattern="([^=]][s]*?|^)(http|https|rstp|ftp|mms|ed2k)://([A-Za-z0-9./=?%-_~`@':+!]*)"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=strMatch.SubMatches(0)

tmpStr2=strMatch.SubMatches(1)

tmpStr3=checkURL(strMatch.SubMatches(2))

strContent=replace(strContent,strMatch.Value,tmpStr1&"<a href="""&tmpStr2&"://"&tmpStr3&""" target=""_blank"">"&tmpStr2&"://"&tmpStr3&"</a>",1,-1,0)

Next

're.Pattern="(^|s)(www.S+)"

'strContent=re.Replace(strContent,"$1<a href=""http://$2"" target=""_blank"">$2</a>")

End IF

IF Not DisUBB=1 Then

IF Not DisIMG=1 Then

re.Pattern="([img])(.[^]]*)[/img]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=(strMatch.SubMatches(1))

strContent=replace(strContent,strMatch.Value,"<img src="""&tmpStr1&""" border=""0"" alt=""""/>",1,-1,0)

Next

re.Pattern="[img=(left|right|center|absmiddle|)](.[^]]*)([/img])"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=strMatch.SubMatches(0)

tmpStr2=checkURL(strMatch.SubMatches(1))

strContent=replace(strContent,strMatch.Value,"<img align="""&tmpStr1&""" src="""&tmpStr2&""" border=""0"" alt=""""/>",1,-1,0)

Next

re.Pattern="[img=(d*|),(d*|)](.[^]]*)[/img]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=strMatch.SubMatches(0)

tmpStr2=strMatch.SubMatches(1)

tmpStr3=checkURL(strMatch.SubMatches(2))

strContent=replace(strContent,strMatch.Value,"<img width="""&tmpStr1&""" height="""&tmpStr2&""" src="""&tmpStr3&""" border=""0"" alt=""""/>",1,-1,0)

Next

re.Pattern="[img=(d*|),(d*|),(left|right|center|absmiddle|)](.[^]]*)([/img])"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=strMatch.SubMatches(0)

tmpStr2=strMatch.SubMatches(1)

tmpStr3=strMatch.SubMatches(2)

tmpStr4=checkURL(strMatch.SubMatches(3))

strContent=replace(strContent,strMatch.Value,"<img width="""&tmpStr1&""" height="""&tmpStr2&""" align="""&tmpStr3&""" src="""&tmpStr4&""" border=""0"" alt=""""/>",1,-1,0)

Next

else

re.Pattern="([img])(.[^]]*)[/img]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(1))

strContent=replace(strContent,strMatch.Value,"<a href="""&tmpStr1&""" target=""_blank"" title="""&tmpStr1&"""><img src=""images/image.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)

Next

re.Pattern="[img=(left|right|center|absmiddle|)](.[^]]*)([/img])"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=strMatch.SubMatches(0)

tmpStr2=checkURL(strMatch.SubMatches(1))

strContent=replace(strContent,strMatch.Value,"<a href="""&tmpStr2&""" target=""_blank"" title="""&tmpStr2&"""><img src=""images/image.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)

Next

re.Pattern="[img=(d*|),(d*|)](.[^]]*)[/img]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=strMatch.SubMatches(0)

tmpStr2=strMatch.SubMatches(1)

tmpStr3=checkURL(strMatch.SubMatches(2))

strContent=replace(strContent,strMatch.Value,"<a href="""&tmpStr3&""" target=""_blank"" title="""&tmpStr3&"""><img src=""images/image.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)

Next

re.Pattern="[img=(d*|),(d*|),(left|right|center|absmiddle|)](.[^]]*)([/img])"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=strMatch.SubMatches(0)

tmpStr2=strMatch.SubMatches(1)

tmpStr3=strMatch.SubMatches(2)

tmpStr4=checkURL(strMatch.SubMatches(3))

strContent=replace(strContent,strMatch.Value,"<a href="""&tmpStr4&""" target=""_blank"" title="""&tmpStr4&"""><img src=""images/image.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)

Next

End IF

'-----------多媒体标签----------------

re.Pattern="[(swf|wma|wmv|rm|ra|qt)(=d*?|)(,d*?|)]([^<>]*?)[/(swf|wma|wmv|rm|ra|qt)]"

Set strMatchs=re.Execute(strContent)

dim strType,strWidth,strHeight,strSRC,TitleText

For Each strMatch in strMatchs

RAndomize

strType=strMatch.SubMatches(0)

if strType="swf" then

TitleText="<img src=""images/flash.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>Flash动画"

elseif strType="wma" then

TitleText="<img src=""images/music.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>播放音频文件"

elseif strType="wmv" then

TitleText="<img src=""images/mediaplayer.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>播放视频文件"

elseif strType="rm" then

TitleText="<img src=""images/realplayer.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>播放real视频流文件"

elseif strType="ra" then

TitleText="<img src=""images/realplayer.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>播放real音频流文件"

elseif strType="qt" then

TitleText="<img src=""images/mediaplayer.gif"" alt=""""margin:0px 2px -3px 0px"" border=""0""/>播放mov视频文件"

end if

strWidth=strMatch.SubMatches(1)

strHeight=strMatch.SubMatches(2)

if (len(strWidth)=0) then

strWidth="400"

else

strWidth=right(strWidth,(len(strWidth)-1))

end if

if (len(strHeight)=0) then

strHeight="300"

else

strHeight=right(strHeight,(len(strHeight)-1))

end if

strSRC=checkURL(strMatch.SubMatches(3))

rndID="temp"&Int(100000 * Rnd)

strContent= Replace(strContent,strMatch.Value,"<divUBBPanel""><divUBBTitle"">"&TitleText&"</div><divUBBContent""><a id="""+rndID+"_href"" href=""javascript:MediaShow('"+strType+"','"+rndID+"','"+strSRC+"','"+strWidth+"','"+strHeight+"')""><img name="""+rndID+"_img"" src=""images/mm_snd.gif""margin:0px 3px -2px 0px"" border=""0"" alt=""""/><span id="""+rndID+"_text"">在线播放</span></a><div id="""+rndID+"""></div></div></div>")

Next

Set strMatchs=nothing

re.Pattern="([mid])(.[^]]*)[/mid]"

strContent= re.Replace(strContent,"<embed src=""$2"" height=""45"" width=""314"" autostart=""0""></embed>")

'-----------常规标签----------------

re.Pattern = "[url=(.[^]]*)](.[^[]*)[/url]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

tmpStr2=strMatch.SubMatches(1)

strContent=replace(strContent,strMatch.Value,"<a target=""_blank"" href="""&tmpStr1&""">"&tmpStr2&"</a>",1,-1,0)

Next

re.Pattern = "[url](.[^[]*)[/url]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

strContent=replace(strContent,strMatch.Value,"<a target=""_blank"" href="""&tmpStr1&""">"&tmpStr1&"</a>",1,-1,0)

Next

re.Pattern = "[ed2k=([^r]*?)]([^r]*?)[/ed2k]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

tmpStr2=strMatch.SubMatches(1)

strContent=replace(strContent,strMatch.Value,"<img border="""" src=""images/ed2k.gif"" alt=""""/><a target=""_blank"" href="""&tmpStr1&""">"&tmpStr2&"</a>",1,-1,0)

Next

re.Pattern = "[ed2k]([^r]*?)[/ed2k]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

strContent=replace(strContent,strMatch.Value,"<img border="""" src=""images/ed2k.gif"" alt=""""/><a target=""_blank"" href="""&tmpStr1&""">"&tmpStr1&"</a>",1,-1,0)

Next

re.Pattern = "[email=(.[^]]*)](.[^[]*)[/email]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

tmpStr2=strMatch.SubMatches(1)

strContent=replace(strContent,strMatch.Value,"<a href=""mailto:"&tmpStr1&""">"&tmpStr2&"</a>",1,-1,0)

Next

re.Pattern = "[email](.[^[]*)[/email]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

strContent=replace(strContent,strMatch.Value,"<a href=""mailto:"&tmpStr1&""">"&tmpStr1&"</a>",1,-1,0)

Next

'-----------字体格式----------------

re.Pattern="[align=(w{4,6})]([^r]*?)[/align]"

strContent=re.Replace(strContent,"<div align=""$1"">$2</div>")

re.Pattern="[color=(#w{3,10}|w{3,10})]([^r]*?)[/color]"

strContent=re.Replace(strContent,"<spancolor:$1"">$2</span>")

re.Pattern="[size=(d{1,2})]([^r]*?)[/size]"

strContent=re.Replace(strContent,"<spanfont-size:$1pt"">$2</span>")

re.Pattern="[font=([^r]*?)]([^r]*?)[/font]"

strContent=re.Replace(strContent,"<spanfont-family:$1"">$2</span>")

re.Pattern="[b]([^r]*?)[/b]"

strContent=re.Replace(strContent,"<strong>$1</strong>")

re.Pattern="[i]([^r]*?)[/i]"

strContent=re.Replace(strContent,"<i>$1</i>")

re.Pattern="[u]([^r]*?)[/u]"

strContent=re.Replace(strContent,"<u>$1</u>")

re.Pattern="[s]([^r]*?)[/s]"

strContent=re.Replace(strContent,"<s>$1</s>")

re.Pattern="[sup]([^r]*?)[/sup]"

strContent=re.Replace(strContent,"<sup>$1</sup>")

re.Pattern="[sub]([^r]*?)[/sub]"

strContent=re.Replace(strContent,"<sub>$1</sub>")

re.Pattern="[fly]([^r]*?)[/fly]"

strContent=re.Replace(strContent,"<marquee width=""90%"" behavior=""alternate"" scrollamount=""3"">$1</marquee>")

End IF

'-----------特殊标签----------------

re.Pattern = "[down=(.[^]]*)](.[^[]*)[/down]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

tmpStr2=strMatch.SubMatches(1)

strContent=replace(strContent,strMatch.Value,"<img src=""images/download.gif"" alt=""下载文件""margin:0px 2px -4px 0px""/> <a href="""&tmpStr1&""" target=""_blank"">"&tmpStr2&"</a>",1,-1,0)

Next

re.Pattern = "[down](.[^[]*)[/down]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

strContent=replace(strContent,strMatch.Value,"<img src=""images/download.gif"" alt=""下载文件""margin:0px 2px -4px 0px""/> <a href="""&tmpStr1&""" target=""_blank"">下载此文件</a>",1,-1,0)

Next

re.Pattern = "[mDown=(.[^]]*)](.[^[]*)[/mDown]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

tmpStr2=strMatch.SubMatches(1)

if len(memName)>0 then

strContent=replace(strContent,strMatch.Value,"<img src=""images/download.gif"" alt=""下载文件""margin:0px 2px -4px 0px""/> <a href="""&tmpStr1&""" target=""_blank"">"&tmpStr2&"</a>",1,-1,0)

else

strContent=replace(strContent,strMatch.Value,"<img src=""images/download.gif"" alt=""只允许会员下载""margin:0px 2px -4px 0px""/> 该文件只允许会员下载! <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a>",1,-1,0)

end if

Next

re.Pattern = "[mDown](.[^[]*)[/mDown]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

tmpStr1=checkURL(strMatch.SubMatches(0))

if len(memName)>0 then

strContent=replace(strContent,strMatch.Value,"<img src=""images/download.gif"" alt=""下载文件""margin:0px 2px -4px 0px""/> <a href="""&tmpStr1&""" target=""_blank"">下载此文件</a>",1,-1,0)

else

strContent=replace(strContent,strMatch.Value,"<img src=""images/download.gif"" alt=""只允许会员下载""margin:0px 2px -4px 0px""/> 该文件只允许会员下载! <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a>",1,-1,0)

end if

Next

re.Pattern="[code](.*?)[/code]"

strContent= re.Replace(strContent,"<divUBBPanel""><divUBBTitle""><img src=""images/code.gif""margin:0px 2px -3px 0px"" alt=""程序代码""/> 程序代码</div><divUBBContent"">$1</div></div>")

re.Pattern="[quote](.*?)[/quote]"

strContent= re.Replace(strContent,"<divUBBPanel""><divUBBTitle""><img src=""images/quote.gif""margin:0px 2px -3px 0px"" alt=""引用内容""/> 引用内容</div><divUBBContent"">$1</div></div>")

re.Pattern="[quote=(.[^]]*)](.*?)[/quote]"

strContent= re.Replace(strContent,"<divUBBPanel""><divUBBTitle""><img src=""images/quote.gif""margin:0px 2px -3px 0px"" alt=""引用来自 $1""/> 引用来自 $1</div><divUBBContent"">$2</div></div>")

re.Pattern="[hidden](.*?)[/hidden]"

if len(memName)>0 then

strContent= re.Replace(strContent,"<divUBBPanel""><divUBBTitle""><img src=""images/quote.gif""margin:0px 2px -3px 0px"" alt=""显示被隐藏内容""/> 显示被隐藏内容</div><divUBBContent"">$1</div></div>")

else

strContent= re.Replace(strContent,"<divUBBPanel""><divUBBTitle""><img src=""images/quote.gif""margin:0px 2px -3px 0px"" alt=""隐藏内容""/> 隐藏内容</div><divUBBContent"">该内容已经被作者隐藏,只有会员才允许查阅 <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a></div></div>")

end if

re.Pattern="[hidden=(.[^]]*)](.*?)[/hidden]"

if len(memName)>0 then

strContent= re.Replace(strContent,"<divUBBPanel""><divUBBTitle""><img src=""images/quote.gif""margin:0px 2px -3px 0px"" alt=""显示被隐藏内容 $1""/> 显示被隐藏内容来自 $1</div><divUBBContent"">$2</div></div>")

else

strContent= re.Replace(strContent,"<divUBBPanel""><divUBBTitle""><img src=""images/quote.gif""margin:0px 2px -3px 0px"" alt=""隐藏内容 $1""/> 隐藏内容</div><divUBBContent"">该内容已经被作者隐藏,只有会员才允许查阅 <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a></div></div>")

end if

re.Pattern="[html](.*?)[/html]"

Set strMatchs=re.Execute(strContent)

For Each strMatch in strMatchs

RAndomize

rndID="temp"&Int(100000 * Rnd)

strContent=Replace(strContent,strMatch.Value,"<divUBBPanel""><divUBBTitle""><img src=""images/html.gif""margin:0px 2px -3px 0px""> HTML代码</div><divUBBContent""><TEXTAREA rows=""8"" id="""&rndID&""">"&UBBFilter(HTMLDecode(strMatch.SubMatches(0)))& "</TEXTAREA><br/><INPUTrunEx('"&rndID&"')"" type=""button"" value=""运行此代码""/> <INPUTdoCopy('"&rndID&"')"" type=""button"" value=""复制此代码""/><br/> [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]</div></div>",1,-1,0)

Next

Set strMatchs=nothing

'-----------List标签----------------

strContent = Replace(strContent,"[list]","<ul>")

re.Pattern = "[list=(.[^]]*)]"

strContent = re.Replace(strContent,"<ullist-style-type:$1"">")

re.Pattern = "[*](.[^[]*)(n|)"

strContent = re.Replace(strContent,"<li>$1</li>")

strContent = Replace(strContent,"[/list]","</ul>")

'-----------表情图标----------------

IF Not DisSM=1 Then

dim log_Smilies,log_SmiliesContent

For Each log_Smilies IN Arr_Smilies

log_SmiliesContent=Split(log_Smilies,"|")

strContent=Replace(strContent,log_SmiliesContent(2)," <img src=""images/smilies/"&log_SmiliesContent(1)&""" border=""0""margin:0px 0px -2px 0px"" alt=""""/>")

Next

End IF

'-----------关键词识别----------------

IF AutoKEY=1 Then

dim log_Keywords,log_KeywordsContent

For Each log_Keywords IN Arr_Keywords

log_KeywordsContent=Split(log_Keywords,"$|$")

IF log_KeywordsContent(3)<>"None" Then

strContent=Replace(strContent,log_KeywordsContent(1),"<a href="""&log_KeywordsContent(2)&""" target=""_blank""><img src=""images/keywords/"&log_KeywordsContent(3)&""" border=""0"" alt=""""/> "&log_KeywordsContent(1)&"</a>")

Else

strContent=Replace(strContent,log_KeywordsContent(1),"<a href="""&log_KeywordsContent(2)&""" target=""_blank"">"&log_KeywordsContent(1)&"</a>")

End IF

Next

End IF

Set re=Nothing

UBBCode=strContent

End IF

End Function

%>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新正则表达式学习
    热门正则表达式学习
    编程开发子分类