REGEXP的运用

www.BCZJ.com【编程之家】 www.bczj.com admin 2007-2-22 14:09:15

<%

function ubbcode(patrn, content)

dim i,regex, match, matches,tempArray()

set regex = new regexp

regex.pattern = patrn

regex.ignorecase = true

regex.global = true

set matches = regex.execute(content)

if matches.count = 0 then

ubbcode = ""

elseif matches.count = 1 then '只有一次匹配,则直接返回

for each match in matches

ubbcode = regex.Replace(match.Value,"$2")

next

else

redim tempArray(matches.count) '匹配的次数很多,则返回数组

i = 0

for each match in matches

tempArray(i) = regex.Replace(match.Value,"$2")

i=i+1

next

ubbcode = tempArray

end if

set matches = nothing

end function

other_content="[中文名]狮门影业(加拿大)[/中文名][英文]Lions Gate Films Inc.(ca)[/英文名][官方网站] http://www.lionsgate-ent.com[/官方网站]"

obj_patrn = ubbcode("(\[官方网站])(.[^\[]*)(\[\/官方网站\])", other_content)

if(isArray(obj_patrn)) then

txtnet = ""

for j = 0 to ubound(obj_patrn)

if j = 1 then exit for

txtnet = obj_patrn(j) & "," & txtnet

txtnet = replace(txtnet,","," ")

next

elseif obj_patrn <> "" then

txtnet = obj_patrn

else

txtnet = ""

end if

response.Write txtnet

%>

责任编辑: 参与评论
【编程之家】版权所有 www.bczj.com 沪ICP备06025676号 QQ:382611662
Powered By: 上海驰志网络 3.0 Beta