ASP match regular function using Matchs instance _ regular expression
Source: Internet
Author: User
Description
The match object can only be created by using 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.
The following code illustrates the use of the Match object:
Function regexptest (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 case sensitive.
Regex.global = True ' Sets global substitution.
Set matches = Regex.execute (strng) ' performs a search.
For the Match in matches ' traverses the matches collection.
Retstr = retstr & "Match" & I & "found at position"
Retstr = retstr & Match.firstindex & ". Match Value is "'
Retstr = retstr & Match.value & "'." & VbCRLF
Next
Regexptest = Retstr
End Function
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