Copy Code code as follows:
<%
' --------------------------------------------------------------
' Match Object
' The result of the matching search is stored in the match object, providing access to the read-only property that matches the regular expression.
' The match object can only be created through the RegExp object's Execute method, which actually returns a collection of Match objects.
' All of the Match object properties are read-only. When you execute a regular expression, you may produce 0 or more Match objects.
' Each Match object provides access to the string found by the regular expression search, the length of the string, and the location of the matching index.
' 0FirstIndex property, which returns the location of the match in the search string. The FirstIndex property uses an offset from zero, which is relative to the starting position of the search string. In other words, the first character in the string is identified as a character 0
' 0Length property, which returns the length of the match found in the string search.
' 0Value property, which returns the matching value or text found in a search string.
' --------------------------------------------------------------
' Response.Write Regexpexecute ("[Ij]s., IS1 Js2 IS3 is4")
Function Regexpexecute (PATRN, STRNG)
Dim regEx, Match, matches ' Set variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' Sets whether character capitalization is not case-sensitive.
Regex.global = True ' Sets global availability.
SET matches = Regex.execute (strng) ' performs a search.
For the match in matches ' traversal matching collection.
Retstr = retstr & "Match found at position"
Retstr = retstr & Match.firstindex & ". Match Value is ' "
Retstr = retstr & Match.value & "'." & "<BR>"
Next
Regexpexecute = Retstr
End Function
' --------------------------------------------------------------------
' Replace method
' Replaces the text found in the regular expression lookup.
' --------------------------------------------------------------------
' Response.Write Regexpreplace ("Fox", "Cat") & "<BR>" Replaces ' Fox ' with ' cat '.
' Response.Write Regexpreplace (s+) (s+) (s+) "," $3$2$1 ") ' exchange of words.
Function regexpreplace (PATRN, REPLSTR)
Dim regEx, str1 ' Set variable.
STR1 = "The quick brown fox jumped over the lazy dog."
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' Sets whether case insensitive.
Regexpreplace = Regex.Replace (str1, Replstr) ' for replacement.
End Function
' --------------------------------------------------------------------
' Search using the Test method.
' Performs a regular expression search on the specified string and returns a Boolean value
' Indicates if a matching pattern is found. The actual mode of the regular expression search is set by REGEXP the Pattern property of the object.
The ' Regexp.global property has no effect on the Test method.
' If a matching pattern is found, the Test method returns True;
' --------------------------------------------------------------------
' Response.Write regexptest ("function", "important function")
Function regexptest (PATRN, STRNG)
Dim regEx, RetVal ' Set variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = False ' Sets whether case insensitive.
RetVal = regex.test (strng) ' performs a search test.
If RetVal Then
Regexptest = "Find one or more matches. "
Else
Regexptest = "no match found. "
End If
End Function
%>