Use ASP for Regular Expressions

Source: Internet
Author: User

Copy codeThe Code is as follows: <%
'--------------------------------------------------------------
'Match object

'Matched search results are stored in the Match object, providing access to read-only attributes matching regular expressions.
'Match objects can only be created through the Execute method of RegExp objects. This method actually returns a set of Match objects.
'All the matching object attributes are read-only. When executing a regular expression, zero or multiple Match objects may be generated.
'Each Match object provides the access to the string found by the regular expression, the length of the string, and the matching index location.
'○ FirstIndex attribute, returns the matched position in the search string. The FirstIndex attribute uses the offset calculated from zero. The offset is relative to the start position of the search string. In other words, the first character in the string is identified as 0
'○ Length attribute, returns the Length of the matched string in the string search.
'○ Value attribute, returns the matched 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 'to create a variable.
SET regEx = New RegExp 'to create a regular expression.
RegEx. Pattern = patrn 'setting mode.
RegEx. IgnoreCase = true' is used to set whether to be case insensitive.
RegEx. Global = true' to set Global availability.
SET Matches = regEx. Execute (strng) 'to Execute the search.
For Each Match in Matches 'traverses the matching set.
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
'Replace 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 word pairs.
Function RegExpReplace (patrn, replStr)
Dim regEx, str1' create a variable.
Str1 = "The quick brown fox jumped over the lazy dog ."
SET regEx = New RegExp 'to create a regular expression.
RegEx. Pattern = patrn 'setting mode.
RegEx. IgnoreCase = true' is used to set whether to be case insensitive.
RegExpReplace = regEx. Replace (str1, replStr) 'to Replace.
End Function

'--------------------------------------------------------------------
'Use the Test method to search.
'Perform a regular expression search on the specified string and return a Boolean value.
'Indicates whether a matching mode is found. The actual Pattern of Regular Expression search is set through the Pattern attribute of the RegExp object.
The 'regexp. global' attribute has no effect on the Test method.
'If the matching mode is found, the Test method returns True; otherwise, False is returned.
'--------------------------------------------------------------------
'Response. Write RegExpTest ("function", "Important Function ")
Function RegExpTest (patrn, strng)
Dim regEx, retVal 'to create a variable.
SET regEx = New RegExp 'to create a regular expression.
RegEx. Pattern = patrn 'setting mode.
RegEx. IgnoreCase = false' specifies whether to enable case sensitivity.
RetVal = regEx. Test (strng.
If retVal Then
RegExpTest = "one or more matches are found. "
Else
RegExpTest = "no matching found. "
End If
End Function
%>

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.