Asp Regular Expressions

Source: Internet
Author: User

Copy codeThe Code is as follows: Dim re
Set re = new RegExp 'create a RegExp instance
Re. Pattern = "AB + c" 'defines the regular expression text. You can replace the regular expression here.
Dim myString
MyString = "abcefg" 'defines the string to be matched and can be replaced
Response. write (re. Execute (myString) (0) 'to test the matching and write the result.

Copy codeThe Code is as follows: <%
Dim re
Set re = new RegExp 'create a RegExp instance
Re. Pattern = "\ w +" 'defines the regular expression text
Dim myString
MyString = "VBScript version 5.6 provides feature new features ."
'To test the matching and write whether the matching is successful
If re. Test (myString) Then
Response. write ("matched! ")
Else
Response. write ("matching failed! ")
End If
%>

Copy codeThe Code is as follows: <%
Dim re
Set re = new RegExp 'create a RegExp instance
Re. Pattern = "\ s" 'defines the regular expression text, which matches the blank space.
Dim myString
MyString = "VBScript version 5.6 provides feature new features ."
MyString = re. replace (myString, "-") 'replace the blank with-, and return the replaced string.
'Write the result
Response. write (myString)
%>

Copy codeThe Code is as follows: <%
Dim re
Set re = new RegExp 'create a RegExp instance
Re. Global = True
Re. Pattern = "\ s" 'defines the regular expression text, which matches the blank space.
Dim myString
MyString = "VBScript version 5.6 provides feature new features ."
MyString = re. replace (myString, "-") 'replace the blank with-, and return the replaced string.
'Write the result
Response. write (myString)
%>

Copy codeThe Code is as follows: <%
Dim re
Set re = new RegExp 'create a RegExp instance
Re. Global = True
Re. Pattern = "(\ w +)-(\ w +)" 'defines the regular expression mode text
Dim myString
MyString = "flip-flop"
MyString = re. replace (myString, "$1-$2 ")
'$1 indicates the first \ w +, $2 indicates 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 codeThe Code is as follows: <%
Dim re
Set re = new RegExp 'create a RegExp instance
Re. Global = True
Re. Pattern = "(\ S +) (\ s +) (\ S +)" 'defines the regular expression mode text
Dim myString
MyString = "flip flop"
MyString = re. replace (myString, "$3 $2 $1 ")
'$1 indicates the first \ S +, $3 indicates the second \ S +, $2 indicates \ s +,
'So $3 $2 $1 is equivalent to flop flip
'Write the result
Response. write (myString)
%>

Copy codeThe Code is as follows: <%
Dim re
Set re = new RegExp 'create a RegExp instance
Re. Global = True
Re. Pattern = "\ w +" 'defines the Regular Expression Pattern text
Dim myString
MyString = "VBScript version 5.6 provides feature new features ."
Set Matches = re. Execute (myString) 'to Execute a search. This Set is used to save matching results.
'Perform the Matching Test and write the results
'Iteration Matches set
For Each Match in Matches
'Write the result
Response. write (Match. FirstIndex & "-" & (Match. FirstIndex + Match. Length) & "& Match. Value &" <br/> ")
Next
%>

Copy codeThe Code is as follows: <%
Dim re
Set re = new RegExp 'create a RegExp instance
'Re. Global = True comment out this line
Re. Pattern = "\ w +" 'defines the Regular Expression Pattern text
Dim myString
MyString = "VBScript version 5.6 provides feature new features ."
Set Matches = re. Execute (myString) 'to Execute a search. This Set is used to save matching results.
'Perform the Matching Test and write the results
'Iteration Matches set
For Each Match in Matches
'Write the result
Response. write (Match. FirstIndex & "-" & (Match. FirstIndex + Match. Length) & "& Match. Value &" <br/> ")
Next
%>

Copy codeThe Code is 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 an SQL CREATE TABLE statement
Set oCmd. ActiveConnection = oConn
OCmd. CommandText = "create table NewEmployees (firstName nvarchar (50), lastName nvarchar (50), EmpType nvarchar (50 ))"
'Create a data table.
OCmd. Execute
Response. Write ("operation successful! ")
%>
<%
'Explicitly close the connection
OConn. Close
Set oConn = Nothing
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.