日期:2014-05-16 浏览次数:20951 次
<%
sData="开头<!-- Begin --><!-- Begin --><!-- /End --><!-- Begin -->This is a content from X to Y.<!-- /End -->"
response.write "<div>"&Server.Htmlencode(sData)&"</div>"
Dim objRegExp,MyPattern,MatCount
Dim NewString
Set objRegExp=New RegExp '创建对象
objRegExp.IgnoreCase=True '是否忽略大小写 True False
objRegExp.Global=True '字符串中全局匹配 True False
objRegExp.MultiLine = False '是否多行 True False
MyPattern="<!-- Begin -->([^(Begin)]*)<!-- /End -->"
objRegExp.Pattern=MyPattern '正则表达式模式
Set MyMatches=objRegExp.Execute(sData)
MatCount=MyMatches.Count
response.write "<div>匹配到个数=["&MatCount&"]</div>"
For Each MyMatch In MyMatches
response.write "<div>项目["&Server.Htmlencode(MyMatch)&"]</div>"
Next
response.write "<hr/>"
sData=objRegExp.Replace(sData,"【被替换了】")
response.write "<div>"&Server.Htmlencode(sData)&"</div>"
%>
sData="开头<!-- Begin --><!-- Begin --><!-- /End --><!-- Begin -->This is a content from X to Y.<!-- /End -->"
response.write "<div>"&Server.Htmlencode(sData)&"</div>"
Dim objRegExp,MyPattern,MatCount
Dim NewString
Set objRegExp=New RegExp '创建对象
objRegExp.IgnoreCase=True '是否忽略大小写 True False
objRegExp.Global=True '字符串中全局匹配 True False
objRegExp.MultiLine = False '是否多行 True False
MyPattern="<!-- Begin -->((?:(?!<!-- Begin -->)[\d\D])*)<!-- /End -->"
objRegExp.Pattern=MyPattern '正则表达式模式
Set MyMatches=objRegExp.Execute(sData)
MatCount=MyMatches.Count
response.write "<div>匹配到个数=["&MatCount&"]</div>"
For Each MyMatch In MyMatches
response.write "<div>项目["&Server.Htmlencode(MyMatch)&"]</div>"
Next
response.write "