ASP regular Expressions Use the detailed _ Application skills

Source: Internet
Author: User
Copy Code code as follows:

Dim RE
Set re = new RegExp ' Create REGEXP instance
Re. Pattern = "Ab+c" defines regular expression text, you can replace the regular expression here
Dim myString
myString = "ABCEFG" defines the string to match and can be replaced
Response.Write (Re. Execute (myString) (0)) ' matches the test and writes out the result

Copy Code code as follows:

<%
Dim RE
Set re = new RegExp ' Create REGEXP instance
Re. Pattern = "\w+" defines regular expression text
Dim myString
myString = "VBScript version 5.6 provides many new features."
' Match test and write whether the match was successful
If Re. Test (myString) Then
Response.Write ("Match success!") ")
Else
Response.Write ("Match not successful!") ")
End If
%>

Copy Code code as follows:

<%
Dim RE
Set re = new RegExp ' Create REGEXP instance
Re. Pattern = "\s" defines regular expression text, here is matching whitespace
Dim myString
myString = "VBScript version 5.6 provides many new features."
myString = Re.replace (myString, "-") ' replaces white space with--returns the replaced string
' Write the result
Response.Write (myString)
%>

Copy Code code as follows:

<%
Dim RE
Set re = new RegExp ' Create REGEXP instance
Re. Global = True
Re. Pattern = "\s" defines regular expression text, here is matching whitespace
Dim myString
myString = "VBScript version 5.6 provides many new features."
myString = Re.replace (myString, "-") ' replaces white space with--returns the replaced string
' Write the result
Response.Write (myString)
%>

Copy Code code as follows:

<%
Dim RE
Set re = new RegExp ' Create REGEXP instance
Re. Global = True
Re. Pattern = "(\w+)-(\w+)" ' defines regular expression mode text
Dim myString
myString = "Flip-flop"
myString = Re.replace (myString, "$1-$2")
' The first \w+,$2 represents the second \w+, the first \w+ matches the flip, the second \w+ matches the flop,
' So $1-$2 is equivalent to flip-flop
' Write the result
Response.Write (myString)
%>

Copy Code code as follows:

<%
Dim RE
Set re = new RegExp ' Create REGEXP instance
Re. Global = True
Re. Pattern = "(\s+) (\s+) (\s+)" ' defines regular expression mode text
Dim myString
myString = "Flip Flop"
myString = Re.replace (myString, "$3$2$1")
' The first \s+,$3 says that the second \s+,$2 represents \s+,
' So $3$2$1 is equivalent to flop flip
' Write the result
Response.Write (myString)
%>

Copy Code code as follows:

<%
Dim RE
Set re = new RegExp ' Create REGEXP instance
Re. Global = True
Re. Pattern = "\w+" defines regular expression mode text
Dim myString
myString = "VBScript version 5.6 provides many new features."
Set matches = Re. Execute (myString) ' performs the search, which is used to save matching results
' To test the match and write the result
' Iteration matches Collection
For the Match in matches
' Write the result
Response.Write (Match.firstindex & "-" & (Match.firstindex + match.length) & "& Match.value &" <b R/> ")
Next
%>

Copy Code code as follows:

<%
Dim RE
Set re = new RegExp ' Create REGEXP instance
' Re. Global = True comment out this line
Re. Pattern = "\w+" defines regular expression mode text
Dim myString
myString = "VBScript version 5.6 provides many new features."
Set matches = Re. Execute (myString) ' performs the search, which is used to save matching results
' To test the match and write the result
' Iteration matches Collection
For the Match in matches
' Write the result
Response.Write (Match.firstindex & "-" & (Match.firstindex + match.length) & "& Match.value &" <b R/> ")
Next
%>

Copy Code code as follows:

<% @language = "VBScript" codepage= "65001"%>
<%
' Create a connection, and create a adodb.command to manipulate the
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
' creates an SQL CREATE TABLE statement
Set ocmd.activeconnection = oconn
Ocmd.commandtext = "Create TA BLE newemployees (firstName nvarchar, lastName nvarchar (), emptype nvarchar) "
Execute create datasheet operation
Ocmd.execut E
Response.Write (The operation was successful!) ")
%>
<%
' explicitly close connection
Oconn.close
Set oconn = Nothing
%>
Related Article

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.