
<%@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>
您發布的評論即表示同意遵守以下條款:
一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會、集體和公民的合法權益;
二、不得發布國家法律、法規明令禁止的內容;互相尊重,對自己在本站的言論和行為負責;
三、本站對您所發布內容擁有處置權。