asp正则表达式使用详解(2)



复制代码 代码如下:

<%
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
%>