| 首页
» Web开发 » ASP
|
| 正则替换的匹配多个项目的解决方法
|
发表于:2005-07-26
阅读:次
|
正则替换的匹配多个项目的解决方法 - IdeaGrace | Web开发 | ASP,IdeaGrace,web,开发,技术,交流,教程 - http://www.ideagrace.com/
<%@ language="vbscript" %>
<%
public Function repString(byVal string,oldS,newS)
Dim reg
set reg=new RegExp
Dim str,oldStr,newStr
Dim aryO(),aryT()
Dim i,j
i=0
str=string
oldStr=oldS
newStr=newS
reg.Pattern="\[u\](.*?)\[\/u\]"
reg.Global=true
reg.IgnoreCase=true
Redim aryO(reg.Execute(str).Count)
Redim aryT(reg.Execute(str).Count)
for each match in reg.Execute(str)
aryO(i)=match.FirstIndex
aryT(i)=match.Value
i=i+1
next
str=reg.Replace(str,"#")
'response.write str&"++++<br/>"
str=Replace(str,"as","<font color=red>as</font>")
for j=0 to UBound(aryT)
str = Replace(str,"#",aryT(j),1,1,1)
' response.write aryT(j)&"++++<br/>"
next
repString=str
End function
stro ="aaghgasfshjgf[u]234234asda[/u]678768[u]basbbb[/u] [u]8888as[/u]r345asgh asj"
response.write stro&"<br/>"
response.write(repString(stro,"as","Hello"))
%>
喜欢本文?那就在线订阅更多文章更新吧!
加入技术论坛讨论
访问IdeaGrace开发者博客
浏览更多java开源项目
IdeaGrace开发者Wiki
更好的浏览体验,
|
|
|
|
|
©2008 Idea Grace
|