Regular expressions use ASP

xiaoxiao2021-03-06  125

<% '----------------------------------------------- --------------- 'match object

The result of 'matching search is to store access to read-only attributes that match regular expressions in the MATCH object. 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 performing regular expressions, zero or more Match objects may occur. 'Each Match object provides access to the string found by the regular expression, the length of the string, and the matching index position, etc. '○ FirstIndex property returns a location that matches in the search string. The firstIndex property uses the 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 '○ Length attribute, returns the length of the match found in the string search. '○ 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' established variables . Set regex = new regexp 'establishes regular expressions. Regex.pattern = PATRN 'Setting mode. Regex.ignorecase = true 'Set whether it is not distinguished by the criteria. Regex.global = true 'Sets global availability. Set matches = regex.execute (strng) 'Executes your search. FOR Each Match In Matches' traverses matching collection. Retstr = RETSTR & "Match Found At position" Retstr = Retstr & Match.firstindex & ". Match value is '" retstr = retrstr & match.value & "'." & "
" Next Regexpexecute = Retstrend Function

'------------------------------------- ----------------- 'Replace method' Replace the text found in the regular expression lookup. '------------------------------------- ------------------ 'Response.write regexpreplace ("fox", "cat") & "
"' Replace 'Fox' is 'CAT'. 'Response.write regexpreplace ("(S ) (S )", "$ 3 $ 2 $ 1")' exchange words pair. Function regexpreplace (PATRN, REPLSTR) DIM Regex, str1 'establishes variables. STR1 = "The Quick Brown Fox Jumped Over The Lazy Dog." SET Regex = New Regexp 'establishes a regular expression. Regex.pattern = PATRN 'Setting mode. Regex.ignoreCase = true 'Set whether it is not case sensitive. Regexpreplace = regex.replace (str1, replstr) 'is replaced. End function '----------------------------------------------- -------------------- 'Use the Test method to search. 'Perform a regular expression search for the specified string, and return a boolean value' indicating whether a matching mode is found. The actual mode of the regular expression search is set by the Pattern property of the Regexp object. 'Regexp.global properties have no effect on the Test method. 'If you find a matching mode, the test method returns true; otherwise returns false' --------------------------------------------------------------------------------------------- --------------------------------- 'Response.write regexptest ("Feature", "Important Features") Function Regexptest (PATRN, STRNG) DIM REGEX, RETVAL 'Establishs variable. Set regex = new regexp 'establishes regular expressions. Regex.pattern = PATRN 'Setting mode. Regex.ignorecase = false 'Set whether it is not case sensitive. Retval = regex.test (strng) 'Performs a search test. If RETVAL THEN regexptest = "Find one or more matchs." Else Regexptest = "did not find a match." End ifend function%>

转载请注明原文地址:https://www.9cbs.com/read-126983.html

New Post(0)