複製代碼 代碼如下:Dim re
Set re = new RegExp '建立RegExp執行個體
re.Pattern = "ab+c" '定義Regex文字,你可以在這裡替換Regex
Dim myString
myString = "abcefg" '定義要匹配的字串,可以進行替換
Response.write(re.Execute(myString)(0)) '進行匹配測試,並寫出結果
複製代碼 代碼如下:<%
Dim re
Set re = new RegExp '建立RegExp執行個體
re.Pattern = "\w+" '定義Regex文字
Dim myString
myString = "VBScript version 5.6 provides many new features."
'進行匹配測試,並寫出是否匹配成功
If re.Test(myString) Then
Response.write("匹配成功!")
Else
Response.write("匹配不成功!")
End If
%>
複製代碼 代碼如下:<%
Dim re
Set re = new RegExp '建立RegExp執行個體
re.Pattern = "\s" '定義Regex文字,這裡是匹配空白
Dim myString
myString = "VBScript version 5.6 provides many new features."
myString = re.replace(myString, "-") '用-替換空白,返回替換後的字串
'寫出結果
Response.write(myString)
%>
複製代碼 代碼如下:<%
Dim re
Set re = new RegExp '建立RegExp執行個體
re.Global = True
re.Pattern = "\s" '定義Regex文字,這裡是匹配空白
Dim myString
myString = "VBScript version 5.6 provides many new features."
myString = re.replace(myString, "-") '用-替換空白,返回替換後的字串
'寫出結果
Response.write(myString)
%>
複製代碼 代碼如下:<%
Dim re
Set re = new RegExp '建立RegExp執行個體
re.Global = True
re.Pattern = "(\w+)-(\w+)" '定義Regex模式文字
Dim myString
myString = "flip-flop"
myString = re.replace(myString, "$1-$2")
'$1表示第一個\w+,$2表示第二個\w+,第一個\w+匹配flip,第二個\w+匹配flop,
'所以$1-$2相當於flip-flop
'寫出結果
Response.write(myString)
%>
複製代碼 代碼如下:<%
Dim re
Set re = new RegExp '建立RegExp執行個體
re.Global = True
re.Pattern = "(\S+)(\s+)(\S+)" '定義Regex模式文字
Dim myString
myString = "flip flop"
myString = re.replace(myString, "$3$2$1")
'$1表示第一個\S+,$3表示第二個\S+,$2表示\s+,
'所以$3$2$1相當於flop flip
'寫出結果
Response.write(myString)
%>
複製代碼 代碼如下:<%
Dim re
Set re = new RegExp '建立RegExp執行個體
re.Global = True
re.Pattern = "\w+" '定義Regex模式文字
Dim myString
myString = "VBScript version 5.6 provides many new features."
Set Matches = re.Execute(myString) '執行搜尋,該集合用來儲存匹配的結果
'進行匹配測試,並寫出結果
'迭代Matches集合
For Each Match in Matches
'寫出結果
Response.write(Match.FirstIndex & "-" & (Match.FirstIndex + Match.Length) & " " & Match.Value & "<br />")
Next
%>
複製代碼 代碼如下:<%
Dim re
Set re = new RegExp '建立RegExp執行個體
're.Global = True 注釋掉這一行
re.Pattern = "\w+" '定義Regex模式文字
Dim myString
myString = "VBScript version 5.6 provides many new features."
Set Matches = re.Execute(myString) '執行搜尋,該集合用來儲存匹配的結果
'進行匹配測試,並寫出結果
'迭代Matches集合
For Each Match in Matches
'寫出結果
Response.write(Match.FirstIndex & "-" & (Match.FirstIndex + Match.Length) & " " & Match.Value & "<br />")
Next
%>
複製代碼 代碼如下:<%@language="vbscript" codepage="65001"%>
<%
'建立一個串連,並且建立一個ADODB.Command用於操作
Dim oCmd,oConn
Set oConn = Server.CreateObject("ADODB.Connection")
Set oCmd = Server.CreateObject("ADODB.Command")
oConn.ConnectionString = "Provider=SQLOLEDB;server = myhost;Initial Catalog = myDatabase;UID=sa;PWD=verysecret;"
oConn.Open
'這裡建立一個SQL CREATE TABLE語句
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = "CREATE TABLE NewEmployees(firstName nvarchar (50),lastName nvarchar (50),EmpType nvarchar (50))"
'執行建立資料表操作
oCmd.Execute
Response.Write("操作成功!")
%>
<%
'顯式的關閉串連
oConn.Close
Set oConn = Nothing
%>