Use of regular expressions ASP

Copy codeThe code is as follows:

‘ ————————————————————–
‘match ‘object

The results of ‘match search are stored in the’ match ‘object, which provides access to the read-only properties of regular expression matching.
The ‘match’ object can only be created by the ‘execute’ method of the ‘regexp’ object, which actually returns a collection of ‘match’ objects.
‘all match object properties are read-only. When a regular expression is executed, zero or more match objects may be generated.
Each ‘match’ object provides access to the string found by regular expression search, the length of the string, and the index position to find a match.
‘○ firstindex’ property, which returns the matching position in the search string. The firstindex property uses an offset from zero relative to the start of the search string. In other words, the first character in the string is identified as the character 0
‘○ length property, which returns the matching length found in string search.
The ‘○ value’ property 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’ create variables.
Set , regex = new , regexp ‘establish a regular expression.
    regEx. Pattern = pattern ‘sets the pattern.
    regEx. Ignorecase = true ‘sets whether characters are case insensitive.
    regEx. Global = true ‘set global availability.
    SET  Matches = regEx. Execute (strng) ‘execute the search.
For # each # match in # matches’ traverse 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 >” ‘replace’ fox ‘with’ cat ‘.
‘ Response. Write , regexpreplace (“(s +) (s +) (s +)”, “$3 $2 $1”) ‘exchange word pairs
Function RegExpReplace(patrn, replStr)
Dim, regex, STR1 ‘create variable.
    str1 = “The quick brown fox jumped over the lazy dog.”
Set , regex = new , regexp ‘establish a regular expression.
    regEx. Pattern = pattern ‘sets the pattern.
    regEx. Ignorecase = true ‘sets whether it is case insensitive.
    RegExpReplace = regEx. Replace (STR1, replstr) ‘.
End Function

‘ ——————————————————————–
Use the ‘test’ method to search.
‘performs a regular expression search on the specified string and returns a Boolean value
‘indicates whether a matching pattern was found. The actual pattern of regular expression search is set through the # pattern # property of the # regexp # object.
‘ RegExp. The global test attribute has no effect on the test method.
‘if a matching pattern is found, the test method returns true; Otherwise, false is returned
‘ ——————————————————————–
‘ Response. Write regexptest (“function”, “important function”)
Function RegExpTest(patrn, strng)
Dim, regex, retval ‘create variable.
Set , regex = new , regexp ‘establish a regular expression.
    regEx. Pattern = pattern ‘sets the pattern.
    regEx. Ignorecase = false ‘sets whether it is case insensitive.
    retVal = regEx. Test (strng) ‘execute the search test.
    If retVal Then
Regexptest = “one or more matches found.”
    Else
Regexptest = “no match found.”
    End If
End Function
%>

Read more here: Source link