<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text ml; charset=gb2312" />
<title>利用正则替换生成html,经典的,可以用数组进行替换</title>
</head>
<body>
<%
dim container
container="{$1,man,hits,hits$} 456545767 $2,title,man,game$ asfasdfa$3,game,hits,man$"
dim regex,objmatch,matches ' 建立变量。
Set regex = New RegExp ' 建立正则表达式。
regex.Global = True ' 设置全局可用性。
regex.IgnoreCase = True ' 设置是否区分字符大小写。
regex.Pattern = "\$[\S\s]+?\$" ' 设置模式
Set matches = regex.Execute(container) '匹配内容
For Each objmatch in matches ' 遍历匹配集合。
'response.Write objmatch.Value & "<br />" '显示数组
'response.write split(replace(objmatch.Value,"$",""),",")(0) & "<br />" '显示数组的第一个数
games=replace(replace(replace(replace(objmatch.Value,"title","标题"),"hits","阅读次数"),"game","内 容"),"man","作者")
'response.write games & "<br>"
response.write split(replace(games,"$",""),",")(0) & "__" & split(replace(games,"$",""),",")(1) & "__" & split(replace(games,"$",""),",")(2) & "__" & split(replace(games,"$",""),",")(3) & "<br>"
Next
response.end
%>
</body>
<html>