復制代碼 代碼如下:
Dim re
Set re = new RegExp '創建RegExp實例
re.Pattern = "ab+c" '定義正則表達式文字,你可以在這裡替換正則表達式
Dim myString
myString = "abcefg" '定義要匹配的字符串,可以進行替換
Response.write(re.Execute(myString)(0)) '進行匹配測試,並寫出結果
復制代碼 代碼如下:
<%
Dim re
Set re = new RegExp '創建RegExp實例
re.Pattern = "\w+" '定義正則表達式文字
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" '定義正則表達式文字,這裡是匹配空白
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" '定義正則表達式文字,這裡是匹配空白
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+)" '定義正則表達式模式文字
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+)" '定義正則表達式模式文字
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+" '定義正則表達式模式文字
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+" '定義正則表達式模式文字
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
%>