主题:  RegExp这个对象如何用?

绿茶

职务:普通成员
等级:8
金币:10.0
发贴:19267
注册:2000/12/28 12:10:01
#12001/7/14 9:10:23
如何用?请细说。



绿茶

职务:普通成员
等级:8
金币:10.0
发贴:19267
注册:2000/12/28 12:10:01
#22001/7/16 7:59:33
我已经知道了。
规则表达式包括要搜索的集合文本和描述如何搜索的特殊字符或命令。要初始化规则表达式搜索,就要生成RegExp对象并设置其Pattern属性。
如搜索"how are you"中的"you"字样:
dim s
dim rgxp
s="how are you"
set rgxp=New RegExp
rgxp.Pattern="you"
response.write rgxp.Text(s &"
'wirtes true

TEST方法返回TRUE或FALSE
EXECUTE返回一个MATCHES
其功能强大,下面则是比较复杂的一个脚本
(转):
function UBBCode(strContent)
if strAllowHTML <> 1 then
strContent = HTMLEncode(strContent)
end if
dim objRegExp
Set objRegExp=new RegExp
objRegExp.IgnoreCase =true
objRegExp.Global=True
if instr(strContent,"[vote]")>0 then
    objRegExp.Pattern="(\[VOTE\])(\S+?)(\[\/VOTE\])"
    strContent=objRegExp.Replace(strContent,"$2")
    strContent=vote(strContent)
end if

objRegExp.Pattern="(\[URL\])(http:\/\/\S+?)(\[\/URL\])"
strContent= objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[URL\])(\S+?)(\[\/URL\])"
strContent= objRegExp.Replace(strContent,"$2")

objRegExp.Pattern="(\[URL=(http:\/\/\S+?)\])(.+?)(\[\/URL\])"
strContent= objRegExp.Replace(strContent,"$3")
objRegExp.Pattern="(\[URL=(\S+?)\])(.+?)(\[\/URL\])"
strContent= objRegExp.Replace(strContent,"$3")

objRegExp.Pattern="(\[EMAIL\])(\S+\@\S+?)(\[\/EMAIL\])"
strContent= objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[EMAIL=(\S+\@\S+?)\])(.+?)(\[\/EMAIL\])"
strContent= objRegExp.Replace(strContent,"$3")

if locktopic="2" then

end if

if strflash= "1" then
objRegExp.Pattern="(\[FLASH\])(.+?)(\[\/FLASH\])"
strContent= objRegExp.Replace(strContent,"$2")
end if

if strIcons = "1" then
objRegExp.Pattern="(\[em(.+?)\])"
strContent=objRegExp.Replace(strContent,"")
' strContent= smile(strContent)
end if

if strIMGInPosts = "1" then
objRegExp.Pattern="(\[IMG\])(\S+?)(\[\/IMG\])"
strContent=objRegExp.Replace(strContent,"")
end if

objRegExp.Pattern="(\[HTML\])(.+?)(\[\/HTML\])"
strContent=objRegExp.Replace(strContent," HTML 代码片段如下:

[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

")

objRegExp.Pattern="(\[color=(.+?)\])(.+?)(\[\/color\])"
strContent=objRegExp.Replace(strContent,"$3")
objRegExp.Pattern="(\[face=(.+?)\])(.+?)(\[\/face\])"
strContent=objRegExp.Replace(strContent,"$3")
objRegExp.Pattern="(\[align=(.+?)\])(.+?)(\[\/align\])"
strContent=objRegExp.Replace(strContent,"
$3
")

objRegExp.Pattern="(\[QUOTE\])(.+?)(\[\/QUOTE\])"
strContent=objRegExp.Replace(strContent,"
quote:
$2
")
objRegExp.Pattern="(\[fly\])(.+?)(\[\/fly\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[move\])(.+?)(\[\/move\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[glow=(.+?),(.+?),(.+?)\])(.+?)(\[\/glow\])"
strContent=objRegExp.Replace(strContent,"$5
")
objRegExp.Pattern="(\[SHADOW=(.+?),(.+?),(.+?)\])(.+?)(\[\/SHADOW\])"
strContent=objRegExp.Replace(strContent,"$5
")

objRegExp.Pattern="(\[i\])(.+?)(\[\/i\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[u\])(.+?)(\[\/u\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[b\])(.+?)(\[\/b\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[fly\])(.+?)(\[\/fly\])"
strContent=objRegExp.Replace(strContent,"$2")

objRegExp.Pattern="(\[size=1\])(.+?)(\[\/size\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[size=2\])(.+?)(\[\/size\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[size=3\])(.+?)(\[\/size\])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(\[size=4\])(.+?)(\[\/size\])"
strContent=objRegExp.Replace(strContent,"$2")

objRegExp.Pattern="(\[center\])(.+?)(\[\/center\])"
strContent=objRegExp.Replace(strContent,"
$2
")
strContent = doCode(strContent, "
    ", "
", "
    ", "
")
strContent = doCode(strContent, "
    ", "
", "
    ", "
")
strContent = doCode(strContent, "
    ", "
", "
    ", "
")
strContent = doCode(strContent, "
  • ", "[/*]", "
  • ", "
  • ")
    strContent = doCode(strContent, "
    ", "
    ", "
    ", "
    ")

    strContent=ChkBadWords(strContent)

    set objRegExp=Nothing
    UBBCode=strContent
    end function

    编辑历史:[这消息被germchen编辑过(编辑时间2001-07-16 08:04:24)]