正则表达式实现UBB代码
- <%
- Function ReplaceTest(patrn,str,replStr)
- Dim regEx, str1
- str1=trim(str)
- Set regEx = New RegExp ' 建立正则表达式
- regEx.Pattern = patrn ' 设置模式
- regEx.IgnoreCase = true ' 设置是否区分大小写
- ReplaceTest = regEx.Replace(str1, replStr) ' 作替换
- set regEx=nothing ‘销毁正则表达式对象
- End Function
- Function UBB(str)
- dim i,temp
- i=1
- temp=""
- do while instr(i,str,"[/"]>=1
- if trim(temp)="" then
- temp=ReplaceTest("(\[i])(\S+)(\[/i])",str,"<i>$2</i>")
- else
- temp=ReplaceTest("(\[i])(\S+)(\[/i])",temp,"<i>$2</i>")
- end if
- temp=ReplaceTest("(\[b])(\S+)(\[/b])",temp,"<b>$2</b>")
- temp=ReplaceTest("(\[big])(\S+)(\[/big])",temp,"<big>$2</big>")
- temp=ReplaceTest("(\[strike])(\S+)(\[/strike])",temp,"<strike>$2</strike>")
- temp=ReplaceTest("(\[sub])(\S+)(\[/sub])",temp,"<sub>$2</sub>")
- temp=ReplaceTest("(\[sup])(\S+)(\[/sup])",temp,"<sup>$2</sup>")
- temp=ReplaceTest("(\[pre])(\S+)(\[/pre])",temp,"<pre>$2</pre>")
- temp=ReplaceTest("(\[u])(\S+)(\[/u])",temp,"<u>$2</u>")
- temp=ReplaceTest("(\[small])(\S+)(\[/small])",temp,"<small>$2</small>")
- temp=ReplaceTest("(\[h1])(\S+)(\[/h1])",temp,"<h1>$2</h1>")
- temp=ReplaceTest("(\[h2])(\S+)(\[/h2])",temp,"<h2>$2</h2>")
- temp=ReplaceTest("(\[h3])(\S+)(\[/h3])",temp,"<h3>$2</h3>")
- temp=ReplaceTest("(\[h4])(\S+)(\[/h4])",temp,"<h4>$2</h4>")
- temp=ReplaceTest("(\[h5])(\S+)(\[/h5])",temp,"<h5>$2</h5>")
- temp=ReplaceTest("(\[h6])(\S+)(\[/h6])",temp,"<h6>$2</h6>")
- temp=ReplaceTest("(\[red])(\S+)(\[/red])",temp,"<font color=red>$2</font>")
- temp=ReplaceTest("(\[email])(\S+)(\[/email])",temp,"<a href=""mailto:$2"" target=_top>$2</a>")
- temp=ReplaceTest("(\[img])(\S+)(\[/img])",temp,"<img src=""$2"">")
- temp=ReplaceTest("(\[url])(\S+)(\[/url])",temp,"<a href=""$2"" target=_top>$2</a>")
- temp=ReplaceTest("(\[#(\S+)])(\S+)(\[/#])",temp,"<font color=$1>$3</font>")
- i=i+1
- loop
- if trim(temp)<>"" then
- UBB=temp
- else
- UBB=str
- end if
- end function
- %>
输出的时候只要调用 UBB(str)就可以了
- 来源:原创
- 版权声明:版权所有,转载时必须以链接形式注明作者和原始出处及本声明。
- 原创作者:lao8
- 本文链接地址:http://www.lao8.org/html/8/2010-1-22/201012213511.html
- 文章名:正则表达式实现UBB代码



