ASP Regular Expression RegExp usage (1/3)

Source: Internet
Author: User
Tags regular expression

Use of RegExp objects:
Copy code code as follows:

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 character case is 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 & "'." & vbCrLf
Next
Regexptest = Retstr
End Function
MsgBox (Regexptest ("is.", "Is1 is2 is3 is4"))

Properties of the RegExp object
Global property
The global property sets or returns a Boolean value that indicates whether the pattern matches all or only the first of the entire search string.
Grammar
Object.global [= True | false]
The object argument is always regexp objects. If the search applies to the entire string, the value of the global property is true, otherwise its value is false. The default setting is true.
Use of the global property (change the value assigned to the global property and observe its effect):
Copy code code as follows:

function Regexptest (patrn, STRNG)
Dim regex ' establishes a variable.
Set regex = new RegExp ' establishes a canonical expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' Sets whether the case of letters is case-sensitive.
Regex.global = True ' Sets the whole property.
Regexptest = Regex.execute (strng) ' performs the search.
End Function
MsgBox (Regexptest ("is.", "Is1 is2 is3 is4"))

IgnoreCase Property
The IgnoreCase property sets or returns a Boolean value that indicates whether the pattern search is case-sensitive.
Grammar
object.ignorecase [= True | false]
The object argument is always a RegExp object. If the search is case-sensitive, the IgnoreCase property is false; otherwise, true. The default value is true.
Use of the IgnoreCase property (change the value given to the IgnoreCase property to observe its effect):
Copy code code as follows:

function Regexptest (PATRN, STRNG)
Dim regex ' establishes a variable.
Set regex = new RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' sets whether case sensitive.
Regexptest = Regex.execute (strng) ' performs the search.
End Function

MsgBox (Regexptest ("is.", "Is1 is2 is3 is4"))

Home 1 2 3 last
Related Article

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.