VBS Tutorial: VBScript Properties-pattern Properties _vbs

Source: Internet
Author: User

Pattern Properties

Sets or returns the regular expression pattern that is searched.

object.Pattern [= "searchstring"]

Parameters

Object

Required option. Always a RegExp object variable.

SearchString

Optional. The regular string expression being searched. It may contain various regular expression characters in the Set section table.

Set up

Special characters and sequences are used when writing patterns for regular expressions. The following table describes the characters and sequences that can be used, and gives an example.

character Description
\ Marks the next character as a special character or literal. For example, "n" matches the character "n". "\ n" matches the line feed character. The sequence "\" and "\" match, "\" ("Match").
^ Matches the start position of the input.
$ Matches the end of the input.
* Matches the previous character 0 or more times. For example, "zo*" can Match "Z", "Zoo".
+ Matches the previous character one or more times. For example, "zo+" can Match "zoo", but does not match "Z".
? Matches the previous character 0 or more times. For example, "A?ve?" Can match "never" in the "VE".
. Matches any character other than the newline character.
(pattern) Match the pattern and remember the match. The matching substring can be used with the Item [0] from the matches collection as the result ... [N] Made. If you want to match the bracket characters (and), you can use "\ (" or "\)".
X| Y Match x or y. For example, "Z|food" can match "Z" or "food". "(z|f) oo" matches "zoo" or "food".
{n} N is a non-negative integer. Matches exactly N times. For example, "o{2}" cannot match "O" in Bob, but can match the first two o in "Foooood".
{n,} N is a non-negative integer. Match at least N times. 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} m and n are non-negative integers. Match at least N times, at most m times. 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 parentheses. For example, "[ABC]" matches "a" in "plain".
[^xyz] A negative character set. Matches any character that is not in this bracket. For example, "[^ABC]" can match "P" in "plain".
[A-z] Represents a character in a range. Matches any character within the specified interval. For example, "[A-z]" matches any of the lowercase alphabetic characters between "a" and "Z".
[^m-z] The character interval of the negation. Matches characters that are not in the specified interval. For example, "[M-z]" matches any character that is not between "M" and "Z".
\b Matches the boundary of a word, which is the position between the word and the space. For example, "er\b" matches "er" in "never", but does not match "er" in "verb".
\b Matches a non word boundary. "ea*r\b" matches the "ear" in "Never early".
\d Matches a numeric character. equivalent to [0-9].
\d Matches a character that is not a number. equivalent to [^0-9].
\f Matches the page break.
\ n Matches the line break character.
\ r Matches the carriage return character.
\s Matches any white character, including spaces, tabs, page breaks, and so on. Equivalent to "[\f\n\r\t\v]".
\s Matches any non-white-space character. Equivalent to "[^ \f\n\r\t\v]".
\ t matches the tab character.
\v Matches the Vertical tab.
\w Matches any word character, including underscores. Equivalent to "[a-za-z0-9_]".
\w Matches any non word character. Equivalent to "[^a-za-z0-9_]".
\num Matches num , where num is a positive integer. References are returned to the remembered match. For example, "(.) \1 "matches two consecutive identical characters.
\ N Match N, where n is a octal value. The octal change value must be 1, 2 or 3 digits long. For example, both "\11" and "\011" match one tab. "\0011" is equivalent to "\001" and "1". The value of the octal converter cannot exceed 256. Otherwise, only the first two characters are considered part of an expression. Allows ASCII code to be used in regular expressions.
\xN Match N, where n is a hexadecimal code-changing value. The hexadecimal transposition value must be exactly two digits long. For example, "\x41" matches "A". "\x041" is equivalent to "\x04" and "1". Allows ASCII code to be used in regular expressions.

Description

The following code illustrates the use of the pattern attribute:

Function RegExpTest(patrn, strng) Dim regEx,Match,Matches'Create a variable. Set regEx = New RegExp 'Establish a generic expression. regEx.Pattern= patrn'Set the mode. regEx.IgnoreCase = True'Sets whether the case is case-sensitive.regEx.Global=True 'Set global availability.set Matches=regEx.Execute(string) 'Duplicate Matching Collection RegExpTest = regEx.Execute(strng)'Perform a search.for each match in matches 'Duplicate Matching CollectionRetStr=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.