VBS Tutorial: VBscript Attribute-Pattern attribute

Source: Internet
Author: User

Pattern attributes

Set or return the regular expression pattern to be searched.

object.Pattern [= "searchstring"]

Parameters

Object

Required. Always oneRegExpObject variable.

Searchstring

Optional. The regular string expression to be searched. It may containSetThe regular expression characters in some tables.

Set

Special characters and sequences are used when writing regular expressions. The following table describes the characters and sequences that can be used and provides examples.

Character Description
\ Mark the next character as a special character or literal value. For example, "n" matches the character "n. "\ N" matches the linefeed. The sequence "\" matches with "\", and "\ (" matches.
^ Match the start position of the input.
$ Matches the end of the input.
* Matches the first character Zero or several times. For example, "zo *" can match "z" and "zoo ".
+ Match the previous character once or multiple times. For example, "zo +" can match "zoo" but does not match "z ".
? Match the first character Zero or once. For example, "? Ve? "Matches" ve "in" never ".
. Match any character other than the line break.
(Pattern) Match with the pattern and remember to match. The matched substring can beMatchesUse Item[0]... [n]. To match the parentheses (and), use "\ (" or "\)".
X|Y MatchXOrY. For example, "z | food" can match "z" or "food ". "(Z | f) oo" matches "zoo" or "food ".
{N} NA non-negative integer. MatchingNTimes. For example, "o {2}" cannot match "o" in "Bob", but it can match the first two o in "foooood.
{N,} NA non-negative integer. Match at leastNTimes. For example, "o {2,}" does not match "o" in "Bob", but matches all o in "foooood. "O {1,}" is equivalent to "o + ". "O {0,}" is equivalent to "o *".
{N,M} MAndNA non-negative integer. Match at leastNTimes, upMTimes. For example, "o {1, 3}" matches the first three o in "fooooood. "O {0, 1}" is equivalent to "o? ".
[Xyz] A character set. Matches one of the characters in the brackets. For example, "[abc]" matches "a" in "plain ".
[^Xyz] A negative character set. Match any character that does not exist in this bracket. For example, "[^ abc]" can match "p" in "plain ".
[A-z] A character in a certain range. Matches any character in the specified range. For example, "[a-z]" matches any lowercase letter between "a" and "z.
[^M-z] A negative character range. Matches a character that is not in the specified range. For example, "[m-z]" matches any character that is not between "m" and "z.
\ B Match the boundary of a word, that is, the position between a word and a space. For example, "er \ B" matches "er" in "never", but does not match "er" in "verb ".
\ B Match the non-word boundary. "Ea * r \ B" matches "ear" in "never early.
\ D Matches a numeric character. It is equivalent to [0-9].
\ D Matches non-numeric characters. It is equivalent to [^ 0-9].
\ F Match with a paging character.
\ N Match with line breaks.
\ R Match the carriage return character.
\ S Matches with any white characters, including spaces, tabs, and pagination characters. It is equivalent to "[\ f \ n \ r \ t \ v]".
\ S Matches any non-blank characters. It is equivalent to "[^ \ f \ n \ r \ t \ v]".
\ T Match with the tab.
\ V Match the vertical tab.
\ W Matches any word characters, including underscores. It is equivalent to "[A-Za-z0-9 _]".
\ W Matches any non-word character. It is equivalent to "[^ A-Za-z0-9 _]".
\Num MatchNum, WhereNumIs a positive integer. Reference back to the remembered match. For example, "(.) \ 1" matches two consecutive identical characters.
\N MatchN, WhereNIs an octal value. The octal value must be 1, 2, or 3 characters long. For example, "\ 11" and "\ 011" Both match a tab. "\ 0011" is equivalent to "\ 001" and "1 ". The octal value cannot exceed 256. Otherwise, only the first two characters are considered part of the expression. ASCII code can be used in regular expressions.
\ XN MatchN, WhereNIs a hexadecimal value. The hexadecimal value must be exactly two digits long. For example, "\ x41" matches "". "\ X041" is equivalent to "\ x04" and "1 ". ASCII code can be used in regular expressions.

Description

The following code illustratesPatternAttribute usage:

Function RegExpTest(patrn, strng)  Dim regEx,Match,Matches         'Create a variable.  Set regEx = New RegExp         'Creates a general expression.  regEx.Pattern= patrn         'Set the mode.  regEx.IgnoreCase = True         'Set whether to be case sensitive.regEx.Global=True                             'Set global availability.set Matches=regEx.Execute(string)             'Repeated matching set  RegExpTest = regEx.Execute(strng)      'Execute the search.for each match in matches                    'Repeated matching setRetStr=RetStr &"Match found at position "RetStr=RetStr&Match.FirstIndex&".Match Value is '"RetStr=RetStr&Match.Value&"'."&vbCRLF NextRegExpTest=RetStrEnd FunctionMsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))

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.