This article is an article I found about the detailed explanation of the use of regular expressions under ASP. I recommend everyone to read it. Copy the code code as follows:
Dim re
Set re = new RegExp 'Create RegExp instance
re.Pattern = ab+c 'Define regular expression literal, you can replace the regular expression here
Dim myString
myString = abcefg 'Define the string to be matched and can be replaced
Response.write(re.Execute(myString)(0)) 'Perform matching test and write the result
Copy the code code as follows:
<%
Dim re
Set re = new RegExp 'Create RegExp instance
re.Pattern = /w+ 'Define regular expression text
Dim myString
myString = VBScript version 5.6 provides many new features.
'Perform a matching test and write whether the match is successful
If re.Test(myString) Then
Response.write(match successful!)
Else
Response.write(matching unsuccessful!)
End If
%>
Copy the code code as follows:
<%
Dim re
Set re = new RegExp 'Create RegExp instance
re.Pattern = /s 'Define regular expression text, here is matching whitespace
Dim myString
myString = VBScript version 5.6 provides many new features.
myString = re.replace(myString, -) 'Replace blanks with - and return the replaced string
'Write the result
Response.write(myString)
%>
Copy the code code as follows:
<%
Dim re
Set re = new RegExp 'Create RegExp instance
re.Global = True
re.Pattern = /s 'Define regular expression text, here is matching whitespace
Dim myString
myString = VBScript version 5.6 provides many new features.
myString = re.replace(myString, -) 'Replace blanks with - and return the replaced string
'Write the result
Response.write(myString)
%>
Copy the code code as follows:
<%
Dim re
Set re = new RegExp 'Create RegExp instance
re.Global = True
re.Pattern = (/w+)-(/w+) 'Define regular expression pattern text
Dim myString
myString = flip-flop
myString = re.replace(myString, $1-$2)
'$1 represents the first /w+, $2 represents the second /w+, the first /w+ matches flip, and the second /w+ matches flop,
'So $1-$2 is equivalent to flip-flop
'Write the result
Response.write(myString)
%>
Copy the code code as follows:
<%
Dim re
Set re = new RegExp 'Create RegExp instance
re.Global = True
re.Pattern = (/S+)(/s+)(/S+) 'Define regular expression pattern text
Dim myString
myString = flip flop
myString = re.replace(myString, $3$2$1)
'$1 represents the first /S+, $3 represents the second /S+, $2 represents /s+,
'So $3$2$1 is equivalent to flop flip
'Write the result
Response.write(myString)
%>
Copy the code code as follows:
<%
Dim re
Set re = new RegExp 'Create RegExp instance
re.Global = True
re.Pattern = /w+ 'Define regular expression pattern text
Dim myString
myString = VBScript version 5.6 provides many new features.
Set Matches = re.Execute(myString) 'Execute search, this collection is used to save matching results
'Perform a matching test and write the results
'Iterate over the Matches collection
For Each Match in Matches
'Write the result
Response.write(Match.FirstIndex & - & (Match.FirstIndex + Match.Length) & & Match.Value & <br />)
Next
%>
Copy the code code as follows:
<%
Dim re
Set re = new RegExp 'Create RegExp instance
're.Global = True comment out this line
re.Pattern = /w+ 'Define regular expression pattern text
Dim myString
myString = VBScript version 5.6 provides many new features.
Set Matches = re.Execute(myString) 'Execute search, this collection is used to save matching results
'Perform a matching test and write the results
'Iterate over the Matches collection
For Each Match in Matches
'Write the result
Response.write(Match.FirstIndex & - & (Match.FirstIndex + Match.Length) & & Match.Value & <br />)
Next
%>
Copy the code code as follows:
<%@language=vbscript codepage=65001%>
<%
'Create a connection and create an ADODB.Command for operation
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
'Create a SQL CREATE TABLE statement here
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = CREATE TABLE NewEmployees(firstName nvarchar (50),lastName nvarchar (50),EmpType nvarchar (50))
'Execute the operation of creating a data table
oCmd.Execute
Response.Write(Operation successful!)
%>
<%
'Explicitly close the connection
oConn.Close
Set oConn = Nothing
%>