直播中
dim patern
dim found
dim str
dim result
patern="(a)|(b)"
str=" A dog fall in love with a cat. Can you believe?"
result=""
call getMatchText(str,result,false)
Response.Write result
sub getMatchText(byref str,byref result,isNeedTrunc)
'on error resume next
Dim regEx, Match, Matches
dim tStr
Set regEx = New RegExp ' 建立正則表達(dá)式?! ?
regEx.Pattern = (patern) ' 設(shè)置模式。
regEx.IgnoreCase = True ' 設(shè)置是否區(qū)分字符大小寫。
regEx.Global = True ' 設(shè)置全局可用性。
Set Matches = regEx.Execute(str) ' 執(zhí)行搜索?! ?
if err.number<>0 then
response.write "錯誤1:" & err.description
err.clear
exit sub
end if
if matches.count <>0 then
dim startIndex
dim myMatchValue
startIndex=1
for each match in matches
if (instr(str,match.value)>0) then
if instr(str,match.value)-50 >0 then
startIndex=instr(str,match.value)-50
else
startIndex=1
end if
myMatchValue=match.value
exit for
end if
next
if isNeedTrunc then
result= (mid(str,startIndex,strLength(myMatchValue)+100))
else
result= (str)
end if
for each match in matches
if not(instr(result,"<font color=red>" & match.value & "</font>")>0) then
result=replace(result,match.value,"<font color=red>" & match.value & "</font>" )
end if
next
found=true
else
found=false
end if
set regEx=nothing
end sub
%>